Wavelet Transform


In this post, I will discuss the Haar wavelet analysis (wavelet transform) in image processing.

Applications of Haar wavelet transform in image processing are Feature extraction, Texture analysis, Image compression etc.





  • Wavelet is time frequency resolutions analysis.
  • As shown in above figure.1  its have the information of different time frequencies of signal.
  • Its like applying a comb of filters bands in signal they are called levels. First we apply full frequency band and have no knowledge of time.
  • Apply filter which have half bandwidth of signal lose some frequency information but  have some knowledge of time resolution called first level decomposition.
  • Further reduce the filter bandwidth will be second level decomposition.

Haar wavelet is made of two filters one is low pass filter and second high pass filter.


Figure. 2 Low pass and high pass filter.

Coefficients of Low pass filter  = [0.707, 0.707]

Coefficients of High pass filter  = [-0.707, 0.707]


Figure. 3



Figure.4 LL band output of Haar wavelet
  • Figure .3 shows the block diagram of first level decomposition.
  • I is image of size m , n. We take the image column vectors (1d) and apply the low pass filter and high pass filter.
  •  Down sample the output and reshape the image I1 of size m, n/2 (size is n/2 because we down sampled the columns by 2).
  • Apply low and high pass filter in row wise in image I1 again down sample the output and reshape the image (m/2,n/2).


Figure.5  1st level decomposition of haar wavelet.
  • Figure. 5 shows the result of haar wavelet decomposition results at first level.
  • LL filter output will proceeds for next level decomposition. As its contains most information of input image and looks almost same at down sampled resolution.
  • HH, LH  and HL will have texture information in vertical, horizontal and ramp directions. HH, LH and HL are called haar features.
  • We can further  decompose the LL image into LL1, LH1, HL1 and HH1 images.


Figure.6 LL band output in 4 level decompostion


Figure.7 2nd Level decomposistion of haar wavelet

MATLAB provide Wavelet Toolbox GUI to perform the wavelet analysis.

Type wevemenu in command window of  MATLAB.

Figure. 8 wavelet tool box GUI in MATLAB


%%%%%%Code Start %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [LL, LH, HL, HH] = haar_wave(image_in)

%% function haar_wave calculate the haar wave decomposition of given imput image
%% Image in :- input gray level image
%% LL :- Low Low band output image
%% LH :- Low High band output image
%% HL :- High Low band output image
%% HH :- High High band output image

image_in = im2double(image_in);
filter_L = [.707, .707];
filter_H = [-.707, .707];
[row, col] = size(image_in);
image_vector = image_in(:);

%% apply low pass filter in one d image column wise image
image_low_pass_1D = filter(filter_L,1,image_vector);
image_high_pass_1D = filter(filter_H,1,image_vector);

% Down sample the image low and high pass image.
temp = 1;
Dimage_low_pass_1D = 0;
Dimage_high_pass_1D = 0;

for i = 1:2:length(image_low_pass_1D)
Dimage_low_pass_1D(temp) = image_low_pass_1D(i);
Dimage_high_pass_1D(temp) = image_high_pass_1D(i);
temp = temp+1;

%% reshape the image in 2 D, size will be row/2 , col
Dimage_low_pass = reshape(Dimage_low_pass_1D,round(row/2), col)’;
Dimage_high_pass = reshape(Dimage_high_pass_1D, round(row/2),col)’;

%% conver the image in 1 D but in column vector, I transpose Dimage_low_paas image above.

Dimage_low_pass_1D = Dimage_low_pass(:);
Dimage_high_pass_1D = Dimage_high_pass(:);

LL_1D = filter(filter_L,1,Dimage_low_pass_1D);
LH_1D = filter(filter_H,1,Dimage_low_pass_1D);

HL_1D = filter(filter_L,1,Dimage_high_pass_1D);
HH_1D = filter(filter_H,1,Dimage_high_pass_1D);

%Down sample the all 1 _d vector images
temp = 1;
DLL_1D = 0;
DLH_1D = 0;
DHL_1D = 0;
DHH_1D = 0;

for i = 1:2:length(LL_1D)
DLL_1D(temp) = LL_1D(i);
DLH_1D(temp) = LH_1D(i);
DHL_1D(temp) = HL_1D(i);
DHH_1D(temp) = HH_1D(i);
temp = temp+1;

%% reshape the images in size row/2 and clo/2

LL = reshape(DLL_1D, round(col/2), round(row/2))’;
LH = reshape(DLH_1D, round(col/2), round(row/2))’;
HL = reshape(DHL_1D, round(col/2), round(row/2))’;
HH = reshape(DHH_1D, round(col/2), round(row/2))’;




                      %% call the haar wavelet function and check the result

clc % clear the screen

clear all % clear all variables

close all % close all MATLAB windows

%% read Image

% set path to read image from system

ImagePath = ‘D:\DSUsers\uidp6927\image_processingCode\lena.jpg’;

img_RGB = imread(ImagePath); % read image from path

img_RGB = im2double(img_RGB); % Convert image to double precision

img_gray = rgb2gray(img_RGB); % convert image to gray

% first level decomposition
[LL, LH, HL, HH] = haar_wave(img_gray);

% second level decomposition
[LL1, LH1, HL1, HH1] = haar_wave(LL);

%% Draw all image

figure, imshow(img_gray);

subplot(2,2,1), imshow(LL,[])
title(‘LL haar wave image’)
subplot(2,2,2), imshow(LH,[])
title(‘LH haar wave image’)
subplot(2,2,3), imshow(HL,[])
title(‘HL haar wave image’)
subplot(2,2,4), imshow(HH,[])
title(‘HH haar wave image’)

subplot(2,2,1), imshow(LL1,[])
title(‘LL1 haar wave image’)
subplot(2,2,2), imshow(LH1,[])
title(‘LH1 haar wave image’)
subplot(2,2,3), imshow(HL1,[])
title(‘HL1 haar wave image’)
subplot(2,2,4), imshow(HH1,[])
title(‘HH1 haar wave image’)

%%%%%%%%%%%%%%%%%Code End %%%%%%%%%%%%%%%%%%%%%%%%%%%%




Happy Learning



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s