Constructing the Gaussian Pyramid

The Gaussian pyramid can be computed with the following steps:

  1. Start with the original image.
  2. Iteratively compute the image at each level of the pyramid, first by smoothing the image (with the Gaussian filter) and then down-sampling it.
  3. Stop at a level where the image size becomes sufficiently small (for example, 1 x 1).
  4. The function to implement the previous algorithm is left as an exercise for the reader; we just need to add a few lines in the following function to complete the implementation:
from skimage.transform import pyramid_reduce 

def get_gaussian_pyramid(image):
'''
input: an RGB image
output: the Gaussian Pyramid of the image as a list
'''
gaussian_pyramid = []
# add code here
# iteratively compute the image at each level of the pyramid with the reduce() function and append
return gaussian_pyramid

The Laplacian pyramid can be computed with the following algorithm:

  1. Start with the Gaussian pyramid and with the smallest image.
  2. Iteratively compute the difference image in-between the image at the current level and the image obtained by first up-sampling and then smoothing the image (with Gaussian filter) from the previous level of the Gaussian pyramid.
  3. Stop at a level where the image size becomes equal to the original image size.
  4. The function to implement the previous algorithm is left as an exercise to the reader as well; we just need to add a few lines in the following function to complete the implementation:
from skimage.transform import pyramid_expand, resize

def get_laplacian_pyramid(gaussian_pyramid):
'''
input: the Gaussian Pyramid of an image as a list
output: the Laplacian Pyramid of the image as a list
'''
laplacian_pyramid = []
# add code here
# iteratively compute the image at each level of the pyramid with the expand() function and append
return laplacian_pyramid

The following code block with the input antelope's image should produce the outputs if the functions are implemented correctly:

image = imread('../images/antelops.jpeg')
gaussian_pyramid = get_gaussian_pyramid(image)
laplacian_pyramid = get_laplacian_pyramid(gaussian_pyramid)

w, h = 20, 12
for i in range(3):
pylab.figure(figsize=(w,h))
p = gaussian_pyramid[i]
pylab.imshow(p), pylab.title(str(p.shape[0]) + 'x' + str(p.shape[1]), size=20), pylab.axis('off')
w, h = w / 2, h / 2
pylab.show()

w, h = 10, 6
for i in range(1,4):
pylab.figure(figsize=(w,h))
p = laplacian_pyramid[i]
pylab.imshow(rgb2gray(p), cmap='gray'), pylab.title(str(p.shape[0]) + 'x' + str(p.shape[1]), size=20)
pylab.axis('off')
w, h = w / 2, h / 2
pylab.show()

Some images from the Gaussian pyramid:

Some images from the Laplacian pyramid:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.170.223