CS194-26: Image Manipulation and Computational Photography

Fun with Frequencies and Gradients!

Denis Li, cs194-26-aem



Overview

In this project, I used different techniques to blend pictures together

Part 1.1: Warmup

Sharpening an image can be done by extracting higher frequencies (image - Gaussian applied to image) from an image and adding it back to the image (with an alpha factor to set the intensity of the sharpening).


blurry image
alpha = 0.5
alpha = 1.0
alpha = 2.0

Part 1.2: Hybrid Images

If we take the higher frequencies of one image and combine it with the lower frequencies of another image, we can get a cool effect where the combined images looks like the first image from up close but the second image from afar. This is because we our eyes pick up the details (higher frequencies) of an image up close but only the general shapes (lower frequencies) of an image from far away. When using color to enhance the effect, I found that it was better to use color for just the low frequency images. here are some examples:

Snow sculpture
nutmeg
hybrid close up
hybrid far away

FFT (frequencies) of the snow sculpture
FFT (frequencies) of nutmeg
FFT (frequencies) of the snow sculpture after high pass filter
FFT (frequencies) of nutmeg after low pass filter
FFT (frequencies) of hybrid image
Darth Vader
Snow sculpture
hybrid close up
hybrid far away
Bird
Duck
hybrid close up
hybrid far away

However this does not work very well if the 2 images are similar.

Orange
Apple
hybrid close up
hybrid far away

Part 1.3: Gaussian and Laplacian Stacks

We can break down to frequencies in an image by using Laplacian stacks

Laplacian Stack for Lincoln Gala



Gaussian Stack for Lincoln Gala



Laplacian Stack for hybrid bird duck



Gaussian Stack for hybrid bird duck



Part 1.4: Multiresolution Blending

We can then use the Laplacian stacks that we made to blend images together seamlessly. We can have a slower transition between the lower frequencies and a faster transition between the higher frequencies so that the images mix together more naturally.


Orange
Apple
Mask
Oraple

Metor
Volleyball game
Mask
Metorball


Obama
Trump
Mask1
Half and half
Mask2
Half and half

We can break down this last image to the laplacian stacks that created it:






Part 2

We can also blend images together in the gradient domain. Since human perception is based off of relative diffidences in color (gradient) if we match the edges gradients of the target image while preserving the gradient of the source image, we are able to paste the source image into the target image pretty seamlessly.

In part 1 we show that we can reconstruct an image using only the gradients and a single pixel intensity:

Original image
Reconstructed image

In part 2 we perform Poisson blending using gradients

In general, this is just one big optimization problem where you are trying to minimizes the difference in gradients between the blended image and the source image as well as the difference in gradients between the edges of the blended image and the edges of the target image. To do this I set up all the constraints in a matrix A and used least squares to find the optimal solution. Since there are so many variable, I used a sparse matrix to seed up the computation.



Source image
Target image
Source mask
Target mask
Pixels directly copied
Poisson blending

Here is another example:


Source image
Target image
Poisson blending

However this does not work too well if the target gradient is too complex or the colors are too different.


Source image
Target image
Poisson blending fails when color is different

Source image
Target image
Poisson blending fails when target image gradient is too complex

Here we compare the results to the Multiresolution blending results from part 1 and see that the Poisson blending does a lot better job with the colors as it uses gradients. However this does result in a change in color of the target image. Poisson blending does better if the colors of the source and target image are similar and Multiresolution blending does better if the colors are different. However, the Multiresolution blending is much faster.



Source image
Target image
Poisson blending
Multiresolution blending
Poisson blending
Multiresolution blending