Firstly I build the Gaussian pyramid for both images. To create the pyramid I filtered the image with a Gaussian filter with standard deviation of 1.6 and of size [5,5]. Through experimentation, values around 1.6 seemed to produce the best results.
After filtering I subtracted the filtered image from the prefiltered one. I stored the residue of the subtraction in a struct, as the first level of the Laplacian pyramid. I stored the filtered image in a different struct that should ultimately contain the entire Gaussian pyramid of the image. After storing both of these, I downsized the filtered image by a factor of 2 using a bilinear interpolation. I repeated these steps as many times as levels were passed in as an input.
Once the pyramids have been created, we can ignore the Gaussian pyramid and focus on the Laplacian. To create the hybrid I took low frequencies of image1 and the high frequencies of image2. The cutoff determined how much low frequency vs. high frequency data I took. For the best results I chose the cutoff to be level 6 out of 10. In this way I placed slightly more emphasis on the higher frequencies. To actually construct the image I took the top of the Gaussian pyramid for image 1 and added onto as many levels of the top of the Laplacian pyramid as indicated by (size-of-Pyramid)-cutoff1-1. The reason why this indexing is a little counter-intuitive is because in my struct I stored the lowest level of the pyramid in the lower indices, and the higher levels in the higher indices.
Once I am done adding the levels of the Laplacian pyramid of image1, I add the remaining levels of image2 onto this sum. So let's say there's a total of 10 levels and the cutoff is 3. I would firstly add the 10th level of the Gaussian pyramid of image 1 with the 10th, 9th and 8th levels of the Laplacian of image 1. Onto this I would add levels 7,6,5,4,3,2,1 of the Laplacian pyramid of image 2. This total sum will yield the final hybrid.
Note that every time I wish to add two levels together I need to upscale the smaller image(the one higher on the pyramid) to ensure that it has the same size as the image from the level below it.
Hybrid Image | N | Cutoff | Jesus-Depp | 10 | 6 | Pitt-Obama | 10 | 6 | Chavan-Presley | 10 | 6 |
Nutmeg-Derek | 10 | 6 |
Marilyn-Einstein | 10 | 7 |
Car-Rhino | 10 | 6 |