INFO 290T Assignment 4
You will implement the classic computer graphics image-blending algorithm described in
P.J. Burt, E.H. Adelson. A Multiresolution Spline With Application to Image Mosaics.
We will provide some
code to get you started. You will fill in the missing pieces in this code.
Image blending takes as input two images and a mask, all of the same size. To keep things simple, we will use grayscale images. Here are some images to get you started, but I encourage you to experiment with your own images:
hf.png,
terminator.png, and
mask.png, which when blended produce the result shown below.
The blending algorithm requires both a Gaussian and Laplacian stack. The difference between a stack and a pyramid is that each pyramid level is downsampled relative to the previous level. In a stack, the pyramid levels are not downsampled so that each pyramid level is of the same size as the original image (and can conveniently each be stored in one 3D matrix). That is, the filtering in a stack is the same as a pyramid, but there is no downsampling. We provide the code for creating a Gaussian stack and you will write the code for creating a Laplacian stack. We also provide code for visualizing a stack.
You will also have to write the function
collapse_laplacian_stack that takes as input a Laplacian stack and collapses it by summing up all the levels to yield a single image.
Once you can construct and collapse stacks, you will write the function
create_blended_stack that takes as input two Laplacian stacks (corresponding to the two input images to be blended) and one Gaussian stack (corresponding to the mask specifying how to blend the images), and returns a blended stack in which each level is a blend of the two images. You will then collapse this blended Laplacian stack to yield the final blended image.
The k
th level of a blended stack is:
(Gk x L1k) + (1-Gk) x L2k, where
Gk is the k
th level of the Gaussian stack (of the mask) and L1
k and L2
k are the k
th levels of the Laplacian stacks (of the two input images).
Your solution must follow the structure of the code provided above; your parts are specified by the comment
# YOUR CODE HERE:....