2D-Discrete Wavelet Transformation and its applications in Digital Image Processing using MATLAB

Koushik Chandrasekaran
6 min readOct 17, 2021

--

Introduction

Spatial domain refers to the normal image space represented as a matrix of pixels. Transformation techniques in this domain are directly operated on image pixel values. The values are manipulated to achieve desired enhancement.

Frequency domain deals with the rate at which these pixel values change in spatial domain. Frequency simply refers to the rate of change of color components in an image. Areas of high frequencies experience rapid color changes, whereas parts that change gradually contain low frequencies.

Unlike spatial domain, we cannot directly operate on the values. The image is first transformed to its frequency distribution before processing it. These frequency components are divided into two major components. High Frequency components that correspond to edges in an image and low frequency component that correspond to smooth regions. The output of this process isn’t an image, rather a transformation. To reconstruct the image to its ideal form, we need to apply inverse transformation on the processed output.

Although there are several mathematical transforms under frequency domain such as the fourier transform, laplace transform, Z transform, this article will explore the wavelet transformation technique that is generally used for image analysis and data compression.

Wavelet Transformation

Okay, so, what exactly are wavelets, and why do we need this transformation? According to Wikipedia,

A wavelet is a wave-like oscillation with an amplitude that begins at zero, increases, and then decreases back to zero. It can typically be visualized as a “brief oscillation” like one recorded by a seismograph or heart monitor.

Wavelets are functions that are concentrated in time and frequency around a certain point. This transformation technique is used to overcome the drawbacks of fourier method. Fourier transformation, although it deals with frequencies, does not provide temporal details. According to Heisenberg’s Uncertainty Principle, we can either have high frequency resolution and poor temporal resolution or vice versa.

This wavelet transform finds its most appropriate use in non-stationary signals. This transformation achieves good frequency resolution for low-frequency components and high temporal resolution for high-frequency components.

This method starts with a mother wavelet such as Haar, Morlet, Daubechies, etc. The signal is then essentially translated into scaled and shifted versions of mother wavelet.

Wavelet Analysis in Image Processing

Wavelet analysis is used to divide information present on an image (signals) into two discrete components — approximations and details (sub-signals).

Decomposition of an image 2-D discrete wavelet transform (2-D DWT). Source — Parida et al. , 2017. Wavelet based transition region extraction for image segmentation. Future Computing and Informatics Journal.

A signal is passed through two filters, high pass and low pass filters. The image is then decomposed into high frequency (details) and low frequency components (approximation). At every level, we get 4 sub-signals. The approximation shows an overall trend of pixel values and the details as the horizontal, vertical and diagonal components.

If these details are insignificant, they can be valued as zero without significant impact on the image, thereby achieving filtering and compression.

Wavelet Transformation in MATLAB

Original Image before transformation

The code snippet below is the implementation of wavelet transformation on an RGB image.

In lines 10–18, we extract the approximate (average image) coefficients and detail coefficients for each color channel. We then apply a simple log transformation appropriately for better visualization. On these partial components, we apply DWT once again to get the final transformation.

The original image above is decomposed into average component (approximate), horizontal component, vertical component and diagonal component as shown below.

Decomposition of image into sub-signals

Wavelet based Denoising of Images

Wavelet transform is a widely used tool in signal processing for compression and denoising. In this section, we will perform denoising of gaussian noise present in an image using global thresholding in the image’s frequency distribution after performing wavelet decomposition. This basically acts as a filter for removal of noise in the frequency domain.

The implementation below is coded in MATLAB. We perform a 3-level discrete wavelet transform on a noisy image and thresholding on the high frequency (detail) components on the frequency domain of the image.

There are two types of thresholding for denoising — hard and soft.

Hard thresholding is the process of setting to zero the coefficients whose absolute values are lower than the threshold λ .

Soft thresholding is another method by first setting to zero coefficients whose absolute values are lower than the threshold λ and then shrinking the nonzero coefficients toward zero.

First we estimate thresholds for all detail coefficients. Once we apply the threshold on all levels, we get the denoised matrices for all the detail components in every level. We use these matrices as coefficients for inverse discrete wavelet transformation to reconstruct the image. The reconstructed image is now denoised.

Block diagram of wavelet denoising technique

The effect of hard-thresholding can be seen on the images shown below.

Before and After denoising using hard-thresholding

Wavelet based Compression of Images

Wavelet compression is a form of data compression well suited for image compression. The idea is to store image data in as little space as possible in a file. Wavelet compression either be lossless or lossy.

In this section we will use wavelet decomposition for compression of images. We use thresholding on detail components after performing a 4-level decomposition. This is done by sorting the wavelet coefficients and retain the first 20%, 10%, 1% and 0.5% largest coefficients and threshold everything else out to zero.

The code below shows the implementation of image compression using a 4-level wavelet decomposition in MATLAB. This can be done easily with the help of inbuilt methods such as wavedec2() and waverec2() to decompose and reconstruct images to/from sub-signals.

The effect of various values of thresholding can be observed below.

Effect of different threshold values on compression

Since we are retaining only a set of coefficients at each level, this indirectly acts as a frequency domain filter (low-pass, high-pass, band-pass, etc. ) which is generally used in fourier transformations. Wavelet compression is a better version of fourier compression since we’re dealing with wavelets.

Conclusion

This article briefly introduced frequency domain transformations and 2D-Discrete Wavelet Decomposition of Images. It then covered two important applications of this transformation for image analysis — denoising and compression. I’ve not covered all explanations in depth since it requires thorough knowledge in signal processing. Nevertheless, I hope you found the content useful. Thanks for your time, happy coding! :)

References

  1. Parida et al. , 2017. Wavelet based transition region extraction for image segmentation. Future Computing and Informatics Journal.
  2. A. Al Jumah, “Denoising of an Image Using Discrete Stationary Wavelet Transform and Various Thresholding Techniques,” Journal of Signal and Information Processing, Vol. 4 No1, 2013, pp. 33–41. doi: 10.4236/jsip.2013.41004.
  3. Anutam, & Rajni, Rajni. (2014). Comparative Analysis of Filters and Wavelet Based Thresholding Methods for Image Denoising. Computer Science & Information Technology. 4. 137–148. 10.5121/csit.2014.4515.
  4. Steve Brunton‘s wavelet transform series on YouTube.

--

--