CS 194-26 Project 3

Blending Using Frequencies and Gradients

Kate Shijie Xu cs194-26-abf

In this project, I explored blending pictures together based on their frequencies and gradients.

Part 1: Frequency Domain

Part 2: Gradient Domain

Sharpen

As a start to the project, I used the unsharp masking technique to sharpen images. Given an image, I first blurred the image using the Gaussian filter, then subtract the blurred version from the original image so to remove its details. I then multiplied the details by some constant alpha, then readd the emphasized details back to the original image so to create the sharpened effect.

Trees
Original
Blurred
Sharpened with a = 1.2
Sharpened with a = 3

The bigger the alpha, the sharper the details will become.

Hybrid Pictures

I created hybrid images using the approach described in this paper written by Oliva, Torralba, and Schyns. Hybrid images are images that look different at different distances, and they are created by blending the high frequency portions of one image with the low-frequency portions of another image. The high frequency portions of the image will dominate perception when the image is seen closeup, while the low frequency portions of the image will dominate when the image is seen at a distance.

1. Porcupine + Bear

Porcupine
Bear
Porcubear

Fourier analysis corresponding to above results

Porcupine
Bear
Result
High Pass
Low Pass

For colored results, I found out that the final result looks better if I use color for both the high frequency and low frequency pictures.

Both Colored
Only high frequency colored
Only low frequency colored

2. Derek + Nutmeg

Derek
Nutmeg
Hybrid Gray
Hybrid Colored

3. Porcupine + Cake: Blending failed in this case mostly because the cake picture is too bright, thus it doesn't feel as if it's dominating perception even when seeing the image close up.

Porcupine
Cake
Fail Gray
Fail Colored

Stacks

I implemented Gaussian and Laplacian stacks. The Gaussian stack is created by convolving the image with the Gaussian filter with increasing sigma at each level. While each layer of the Laplacian stack is created by taking the different between two Gaussian stack layers.

In the examples below, the first row of pictures is the Gaussian stack, and the second row is the Laplacian stack.

1. Braque's Violin and Candlestick
2. Picasso's Portrait of Ambroise Vollard

Multiresolution Blending

In multiresolution blending, I utilized the Gaussian and Laplacian stacks to seamlessly blend two pictures together. I actually used 8 layers for the Gaussian stack because I found that the blending is smoother with layers.

1.Oraple

Gaussian Stacks

Laplacian Stack

Blending Stack

Final Result Stack

Grayscale Result

Apple
Orange
Final Oraple

Colored Result

Apple
Orange
Final Oraple
2. Pretty Face + Nice Suit

Inputs

Pretty Face
Nice Suit
Mask

Final Result Stack

Grayscale Result

Pretty Face
Nice Suit
One Sophisticated Man
3. Starry Waves

Inputs

Kanagawa Oki Nami Ura
Starry Night
Mask

Grayscale Results: As you can see below, directly copying Waves's masked area to Starry Night (left) will cause ugly sharp edges, while the edges are more naturally blurred with multires blending (right). However, multires did not perfectly blend the edges with Starry Night's background, as you can still see awkward gray areas near the tips of the waves.

Direct Copy
Multiresolution Blending

Failed Colored Results: Since multires blending use weighted sum of the source and target images to create new pixels, if the difference between color intensities between the 2 images is great, the blended result is not smooth.

4. Stars in Guangzhou

Inputs

Guangzhou
Northern Sky
Mask
Direct Copy
Multiresolution Blending

Part 2: Gradient Domain Fushion

In this part of the project, I used gradient-domain processing to smoothly blend pictures together. Since people usually care more about the gradient of an image rather than the overall intensity of the image's pixels, we can smoothly blend images together by maximally preserve the gradient of the source image.

Specifically, I implemented the Poisson Blending algorithm based on the following least squares formation:

In this objective function, we're given the pixel intensities of a source image s and a target image t, and we're trying to solve for new pixel intensity values v. Each i is a within the mask, and each j is a neighbor of i. Essentially the first summation of the function is trying to minimize the difference between source and optimal pixel values within the mask, while the second summation is trying to minimize the difference between pixels from the source image that are within the mask and the pixels from the target image that are bordering the mask, so to achieve a smooth blending effect.

Toy Problem

The constraints of this problem specify that the top left corner of the new image should match that of the old image, so the resulting new image has the same gradients as the old image.

Initial
Reconstructed

Possion Blending

0. Revisiting the Oraple
Apple
Orange
Direct Paste
Multiresolution Blending
Poisson Blending
Multiresolution Blending
Poisson Blending

As you can see in the results above, Poisson Blending (right) has a smoother color blending than Multiresolution Blending (left). This is because Poisson Blending tries to maximally preserve the gradient level of the original target image, so it matched the source image's gradient with the target image's gradient.

0.5. Pretty Face + Nice Suit 2.0
Multiresolution Blending
Poisson Blending

In this case, because Poisson Blending tried matching the source image's gradient to the target image's gradient, the face is darker and the highlights from the source image is lost. The colored version also look uneven in color intensity.

Failed Poisson Blending

Thus, I think Poisson Blending should be used if you want an output image that has about the same gradients as the original target image. If you want to keep the gradients from the source image, like the highlights of the face, then you should use multiresolution blending instead.

Extras

1. My sister wants her face on everything.
Pretty Dress
Kid
Mask
Direct Paste
Grayscale Result: Not bad
Colored Result

As you can see above, my sister's face is lighter and matches the mannequin's skin color in the Poisson Blending result, because the gradient level of the target image is maximally perserved.

2. I wished there were fireworks in Guangzhou.
My City
Fireworks in SF
Mask
Direct paste
Grayscale Result
Colored Result

Breakdown of Colored Result

Red Channel
Green Channel
Blue Channel
Final Colored
4. My roommate likes Loki and sparkling water, but the two are not mutually exclusive.
Loki
Sparkling Water
Mask
Loki Approved

Colored version

Red Channel
Green Channel
Blue Channel
Final Colored
5. I didn't realize there was bird poop on the wall behind me until it was too late.
Pretty wall
Bird poop stained wall
Mask
Direct Paste
No more bird poop!
Final Colored

There is a sharp countour edge around the source image in the Direct Paste output (left), which is then smoothly blended together with the background in the Poisson Blended output (middle). In the colored version (right), however, Poisson Blending overly blended the edges of the source image with the background such that the sleeves of the shirt is pink and the left arm is slightly blue.