Gaussian and laplacian pyramids are applying gaussian and laplacian filter in an image in cascade order with different kernel sizes of gaussian and laplacian filter.

- Figure. 1 shows pyramid of image.
- Full image resolution is taken at level 0.
- At each step up level image resolution is down sample by 2. So if starting image size is 256 X 256 at level 0 in level 1 image size will be 128 X 128.

**Gaussian Pyramid :**

- Figure. 2 shows the Gaussian pyramid block diagram of input image.

- Take input image (in_image), apply gaussian filter, output will be level 0 image.

- Down sample the level o image by 2, apply gaussian filter, output will be level 1 image.

- Down sample the level 1 image by 2, apply gaussian filter, output will be level 2 image.

- Similar way we can create full pyramid of gaussian.

- Every level use same Gaussin filter. (If you are down sampling the image by 2 at each level, size of gassuan filter should not be changed)

- Effect of down sampling the image by 2 is equivalent to increasing the bandwidth of gaussian filter by 2.

- Suppose gassuain filter cutoff frequency is F1 in 0 level if we down sample image by 2 gaussian filter cut of frequency will be 2*F1 for down sampled image.

- So by down sampling the image, we are applying different sizes of gaussian in input image. That is also called multi resolution analysis.

**Gaussian pyramids are used in SIFT, Surf, Gabor filters for multi resolution features extractor**

Figure. 3 Gaussian pyramid results

Figure. 3 shows gaussian pyramid results. Level 2 image is much blurred as compared to level 0.

**Laplacian Pyramid: **

- Suppose Level 0, level 1 and level 2 is the output of gaussian pyramid as we discussed above. Figure. 4 shows the block diagram of laplacian pyramid from gaussian pyramid.

- Up sample the gaussian level 1 image by 2 (level 1_2)and subtract the level 1_2 image from level 0 image, output will be laplacian of level 0.

- Upsample the gaussian level 2 image by 2 (level 2_2) and subtract the level 2_2 image from level 1 gaussian image , output will be laplacian of level1.

- Laplacian pyramid try to find out the pass band frequency.

- Suppose gaussian level 0 frequency is f1 and gaussian level 1 frequency is f2, so laplacian level 0 frequency will be f2 – f1.

**Laplacian pyramid used many time in object detection pre processing steps.**

**It can help to compute the optical flow for large motion vector.**

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

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

[row,col,channel] = size(img_gray); % get size of image

h_gauss = fspecial(‘gaussian’,11,1);

% apply gaussian filter to gray image

gauss_level_0 = imfilter(img_gray, h_gauss,’replicate’);

% down sample the gauss_level_0 image by 2 (resize function)

% Apply gaussian filter

gauss_level_1 = imfilter(imresize(gauss_level_0,[round(row/2),round(col/2)]), h_gauss,’replicate’);

% down sample the gauss_level_1 image by 2 (resize function)

% Apply gaussian filter

gauss_level_2 = imfilter(imresize(gauss_level_1,[round(row/4),round(col/4)]), h_gauss,’replicate’);

% down sample the gauss_level_2 image by 2 (resize function)

% Apply gaussian filter

gauss_level_3 = imfilter(imresize(gauss_level_2,[round(row/8),round(col/8)]), h_gauss,’replicate’);

% upsample the gauss_level_1 image by 2(resize function)

% subtract resized gauss_level_1 image from gauss_level_0 image

laplacian_level_0 = gauss_level_0 – imresize(gauss_level_1,[row,col]);

% upsample the gauss_level_2 image by 2(resize function)

% subtract resized gauss_level_2 image from gauss_level_1 image

laplacian_level_1 = (gauss_level_1 – imresize(gauss_level_2,[round(row/2),round(col/2)]));

% upsample the gauss_level_3 image by 2(resize function)

% subtract resized gauss_level_3 image from gauss_level_2 image

laplacian_level_2 = (gauss_level_2 – imresize(gauss_level_3,[round(row/4),round(col/4)]));

% draw all the images

subplot(2,2,1), imshow(img_gray,[])

title(‘input image’)

subplot(2,2,2), imshow(gauss_level_0,[])

title(‘gaussian pyramid level0’)

subplot(2,2,3), imshow(gauss_level_1,[])

title(‘gaussian pyramid level1’)

subplot(2,2,4), imshow(gauss_level_2,[])

title(‘gaussian pyramid level2’)

figure,

subplot(2,2,1), imshow(img_gray,[])

title(‘input image’)

subplot(2,2,2), imshow(laplacian_level_0,[])

title(‘laplacian pyramid level0’)

subplot(2,2,3), imshow(laplacian_level_1,[])

title(‘laplacian pyramid level1’)

subplot(2,2,4), imshow(laplacian_level_2,[])

title(‘laplacian pyramid level2’)

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

Happy Learning

Cheers