The key to Gaussian and Laplacian Pyramid generation is that size of the initial image (known as 'level 0') must be a square image [(2^M)+1]x[(2^M)+1]. Each subsequent level 'n' of the pyramid has a size of [(2^M-n)+1]x[(2^M-n)+1]. The exception to the rule is that when a pyramid eventually reaches a 3x3 size, the next and final level is of size 1x1.
Images of any size can have Gaussian and Laplacian pyramids generated, but their sizes must be padded to "power of 2 plus 1" square. Figure 1 in the results section shows an image padded to 257x257 prior to Laplacian Pyramid generation.
The first step in generating a Laplacian Pyramid is to generate an image's Gaussian Pyramid. Each level of a Gaussian pyramid is of a lower resolution than the previous. A 'reduce()' function was coded in MATLAB to generate each Gaussian level. The reduce operation simply performed two operations: 1) low-pass filtered the image, and 2) discarded odd numbered rows and columns from the filtered image.
Low-pass filtering of the image was accomplished by taking a weighted average of a 5x5 region surrounding each image pixel. To increase computation efficiency, a separable equivalent weighting function was used to perform the 5x5 weighted average. By first convolving an image with a 1x5 weighting function, the 'horizontal' weighted average of the image was performed. Next, convolving the 'horizontally' averaged result with the transpose of the 1x5 (i.e. a '5x1') weighting function performs the 'vertical' weighted averaging. A Gaussian-like weighting function with values of [.05 .25 .5 .25 .05] was used by the 'reduce()' function.
To help reduce artifacts produced from the image boundaries, the image being filtered has it's edges "thickened" by reflecting the image boundary pixels prior to filtered. After filtering has been completed, only the "thickened" image is cropped back to it's original size.
In order to generate a Laplacian pyramid, an 'expand()' function must be implemented that takes a given image and roughly doubles it's resolution. The 'expand()' operation tries to reverse the resolution reduction that results from the 'reduce()' operation. The 'expand()' operation simply inserts 0's in rows and columns between pairs of pixel values and then performs a low-pass filtering operation identical to the one described in the 'reduce()' function.
The 'expand()' operations low-pass filtering described above, without adjusting the gain, will reduce the average intensity by a factor of 4 from one level to the next. This can be explained by examining the weighted average of a 5x5 region. After inserting 0's, an uniform image could have a 5x5 region of:
[100 __0 100 __0 100]
[__0 100 __0 100 __0]
[100 __0 100 __0 100]
[__0 100 __0 100 __0]
[100 __0 100 __0 100]
*OR*
[__0 100 __0 100 __0]
[100 __0 100 __0 100]
[__0 100 __0 100 __0]
[100 __0 100 __0 100]
[__0 100 __0 100 __0]
After 'horizontal' and 'vertical' averaging with the kernel [.05 .25 .5 .25 .05], the resulting center pixel would have an intensity of "25". A gain of 4 is necessary in order for the image intensity to remain at 100.
With the definition of 'reduce()' and 'expand()' operations, Laplacian pyramid generation can be shown by the following algorithm:
G'level 0' = original image
G'level X' = reduce('level X-1'), where X > 0
L'level X' = G'level X' - expand('level X+1'), where X >=0
G'level X' = gaussian pyramid 'level X'
L'level X' = laplacian pyramid 'level X'
The exception to the above algorithm is for the Laplacian level that consists of a single pixel (i.e. 1x1). The last level of the Laplacian is simply the corresponding single pixel Gaussian level (i.e. L'level Y' = G'level Y').
Generating an output image by 'collapsing' a Laplacian pyramid is accomplished by recursively collapsing each lower level using the algorithm:
Collapse('level X') = L'level X' + expand( collapse('level X+1') )
Splining two images simply requires: 1) generating a Laplacian pyramid for each image, 2) generating a Gaussian pyramid for the bitmask indicating how the two images should be merged, 3) merging each Laplacian level of the two images using the bitmask from the corresponding Gaussian level, and 4) collapsing the resulting Laplacian pyramid.
i.e.
GS = Gaussian pyramid of bitmask
LA = Laplacian pyramid of image "A"
LB = Laplacian pyramid of image "B"
therefore, "Lout = (GS)LA + (1-GS)LB"
to TOP
Figure 1: a) Image used to test the reversibility of Laplacian Pyramid generation [LEFT}. The image dimensions of 225x323 doesn't allow generation of a reversible Laplacian. b) As a test, the upper segment of the image was padded to 257x257 [CENTER]. c) The final image illustrates that perfect image reconstruction can be obtained by first creating and then collapsing a Laplacian Pyramid [RIGHT]. (test3.m).
Figure 2: Shows Gaussian pyramid levels 0-8 of Figure 1b.
Figure 3: Shows Laplacian pyramid levels 0-8 of Figure 1b.
Figure 4: a) original image #1 [LEFT], b) mask used to combine image #1 & #2 [CENTER], c) original image #2 [RIGHT].
Figure 5: a) image #1 & #2 merged w/o splining [LEFT], b) image #1 & #2 merged w/ splining [RIGHT] (test4.m).
Figure 6: An old "1st attempt" splining of image #1 & #2 using a bitmask that ran through the middle of both images. This illustrates that a poor choice for a bitmask dramatically reduces the quality of the splined image.