Burt-Adelson Pyramid

Here is a demonstration of how to compute the well-known Burt-Adelson image pyramid [P. Burt and E. H. Adelson, “The Laplacian Pyramid as a Compact Image Code,” IEEE Transactions on Communication 31 (1983) 532-540]. Note that by using Mathematica’s powerful functional programming constructs, the Gaussian and Laplacian pyramids are computed with one-line programs.

This loads the package.

<< ImageProcessing`

This loads and displays an example image.

Show[Graphics[img = ImageRead["cameraman.tif"]]];

This defines a commonly used generating kernel.

ker = 
      Outer[Times, {0.05, 0.25, 0.4, 0.25, 0.05}, {0.05, 0.25, 0.4, 0.25, 
          0.05}, 1]

This constructs the Gaussian pyramid by repeatedly convolving an image with the generating kernel and decimating the result. A pure function is used to define the operation at each step of the iteration inside NestList.

gaussPyramid = 
      NestList[Decimate[
            DiscreteConvolve[#, ker, Circular -> True, 
              Centered -> True]] &, img, 5]

As expected, the images have dimensions that decrease by a factor of four at each level of the pyramid.

ImageDimensions /@ gaussPyramid

This shows the images in a graphics array.

Show[
        GraphicsArray[Partition[Graphics /@ gaussPyramid, 3]]];

The differences of images at successive levels of the Gaussian pyramid define the Laplacian pyramid. To calculate a difference, the image at a higher level in the pyramid must be increased in size by a factor of four prior to subtraction. This computes the pyramid.

lapPyramid = 
      Join[Map[#[[1]] - Interpolate[#[[2]]] &, 
          Partition[gaussPyramid, 2, 1]], {gaussPyramid[[6]]}]

This shows the six levels of the Laplacian pyramid.

Show[GraphicsArray[Partition[Graphics /@ %, 3]]];

The original image may be reconstructed from the Laplacian pyramid by reversing the previous steps. This interpolates and adds the images at successive levels of the pyramid beginning with the lowest level.

Reverse[lapPyramid];
Fold[Interpolate[#1] + #2 &, First[%], Rest[%]]

% == img

Clear[img, gaussPyramid, lapPyramid, ker]