Bradley Qu

CS 194-26: Project 3

Fun with Frequencies and Gradients

Introduction

        I manipulate frequencies and gradients to achieve realistic image blending. First I made hybrid images that have high and low frequencies from two different images. I then did image splines by bleding different frequencies at different magnitudes. Finally, I implemented gradient blending for seamless blending of details at the cost of color accuracy.

Warm Up

         Warmup was to apply an unsharp mask to an image of choice. I chose a blurry cityscape to show how unsharp filter does not actually sharpen an image and only gives an illusion of sharpness. In really blurry images, it just causes clipping and noise.

Original
City + 0.05 of sigma 0.6 * dim / 100

Hybrid Images

         Hybrid images are Images with high freqiencies from one image and low frequencies from another. My implementation makes use of the starter code to align images. I then take a DFT on each image and apply a low pass gaussian gaussian filter on one for low frequencies and a high pass impulse minuse gaussian on the another for high frequencies.

Results

High Freq Cat (sig 10000) Low Freq Derek (sig 10000)
Trump
Hillary
High Freq Hillary (sig 1000000) Low Freq Trump (sig 700000)
FAILURE!!!!!! Hillary has mostly high frequency features so she is lost
Peter
Smile
High Freq Peter (sig 1000000) Low Freq Smile (sig 1000000)
Smaller image to see low frequency cry

        The last image is the best result. The high frequency crying features like wrinkles and teeth make it clear that the hybrid is smiling, but from afar, the shadows from the sad face makes it look like he is crying. Here is the frequency analysis:

Peter Freq
Peter Filtered Freq
Peter Filtered
Smile Freq
Smile Filtered Freq
Smile Filtered

Stacks

Gaussian and Laplacian stacks are decompositions of images into frequency bands. They are a great way to visualize the details in the image. My implementation iteratively blurs an image by a constant sigma. The sigma I chose for each stack is 6/1000 * dim where dim is the image dimension.

Reference
1
2
3
4
5 (base)
1
2
3
4
5 (base)
Reference
1
2
3
4
5 (base)
1
2
3
4
5 (base)

Stacks are actually a great way to visualize how hybrid images work. The different images are clearly visible at the different detail levels.

Reference
1
2
3
4
5 (base)
1
2
3
4
5 (base)
Reference
1
2
3
4
5 (base)
1
2
3
4
5 (base)

MultiResolution Blending

Multi-resolution blending is when different frequencies are blended at different magnitudes. This is an extension of Laplacian stacks. It can easily be done by generating two masks, one for each image to be blended and blending those with the Laplacian stack level. The results all use the same sigmas, but there are two: one for the mask blur and the other for the stack blur(0.04, 0.001 respectively).

Apple
Orange
Appange?
Pencil
Plane
Plancil
Cliff
Chair
Cliff Chair
Mask

Toy Problem

         The goal of the toy problem is to reconstruct an image with one pixel value and its gradient. I achieved This by creating a set of linear equations in the form Ax = b. x is what we are trying to solve for which is the pixel value of every pixel in the toy image. A is the gradient equations in the form of "p1 - p2" and b is the result "p1-p2 = grad". Since the image is a square, there can be at most 4 * width * height equations. Thus, I can initialize the matricies and fill them rather than cosntantly stack rows. After construction of the matrices, I prune of empty rows of A and b and use least squares regression to solve for b. Result:

Toy Solution

Poisson Blending

         Poisson blending was a simple extension from the Toy problem. First, kudos to Nikhil Uday Shinde for the python starter code. Using his masking ui, I generate masks for a transformed starter image and centers on the target image. The starter code generates a mask for the second image, but it is unecessary. I construct my matrices the same way as in the toy problem. This time, however, I deal with all three color channels. I also take a first pass through the source image to identify and map x vector variables to pixels. I then construct the equations like normal. Results:

Art Gallery

Source
Mask
Target
Overlay
Result
Source
Mask
Target
Overlay
Result
Source
Mask
Target
Overlay
Result
Source
Mask
Target
Overlay
Result FAIL!!!!!

         The plane failed because there were too many gradients to line up perfectly. Thus, it is much better to use the resolution blending as it is much more difficult to notice the imperfections. Of course, the disadvantage is that the shadows and ground can look weird.