CS 194-26 Project #3: Fun with Frequencies and Gradients!

Yue Zheng



Part 1: Frequency Domain


Part 1.1 Unsharp Masking

The main idea of unsharp masking is that image blurring takes away details from an image, but if we add those details back to the image scaled by a certain factor, the details would be enchanced and we get a "sharper" image. The unsharp mask filter is therefore defined as below:

In my implementation, I used a standard Gaussian filter with sigma set to 10 for my smoothing filter. And I obtained the details by subtracting the smoothed image from the original image. Lastly, I add back the details by scaled by a factor of alpha to the original image.

Results:

The some results of using this technique to sharpen images:

Wheeler (Taken with pinhole camera)


Sharpened (sigma: 10, alpha: 0.6)


Harry


Sharpened (sigma: 10, alpha: 0.3)


Grapefruit


Sharpened (sigma: 10, alpha: 0.85)



Part 1.2: Hybrid Images

Approach:

This part of the assignment is to use the method described in the SIGGRAPH 2006 paper by Oliva, Torralba, and Schyns, to create hybrid images that appear different to human eyes at different distances. The blending method is based on the fact that high frequency tends to dominate perception when it is available, but can't be seen at a distance. Therefore only the low frequency part of the signal can be seen from a distance. To create such hybrid images, I low-pass filter an image using a Gaussian filter to obtain the low frequency image, then high-pass filter another image using the impulse filter minus the gaussian filter to obtain the high frequency image. The two images added together results in a hybrid image that is perceived differently depending on distance.

Results:

Derek


Nutmeg


Hybrid


Dog


Wolf


Hybrid


Failed Example:

The following hybrid is not so satisfactory. Up close, the dog seems to have the man's thick eyebrows, and at a distance, the man still seems to have the dog's wrinkles and folds. This is probably because the man's eyebrows are very thick, but don't aline with any features on the dog's face. And the wrinkles and folds of the dog are too many and too sharp as details to be ignored even from a distance.

Smile


Dog


Hybrid



Favorite Result and its Frequency Analysis:

From the 2D Fourier transforms, we can see that after applying a low-pass filter to the smile image, there are less sharp edges. After applying a high-pass filter to the frown image, it is clear that while the edges remain, most of the other pixels are lost. In other words, only the details are kept after going through the high-pass filter.

Low Frequency Input: Smile


2D Fourier of Input


2D Fourier after applying Low-pass Filter


High Frequency Input: Frown


2D ourier of Input


2D Fourier after applying High-pass Filter


Result:

Large (High Frequency):


Small (Low Frequency):


2D Fourier of hybrid:


Hybrid Images with Color

Nutmeg/Derek


Wolf/Dog


Frown/Smile:



Part 1.3: Gaussian and Laplacian Stacks

In this part, we implement Gaussian and Laplacian stacks and use them to analyze images that contain structure in multiple resolution, including the hybrid images created in the last part. To create a Gaussian stack, I start with the original image as the first level and apply the Gaussian filter to the current level image to obtain the next level, until I reach the desired level. To create a Laplacian stack, each level is obtained by subtracting the next level in the Gaussian stack from the corresponding level of the Gaussian stack. The last level of the Laplacian stack is set to be the same as the last level of the Gaussian stack to preserve the lowest frequencies. To verify the correctness of the stacks, I check that if I add up all the levels in the Laplacian stack, I get back the original image. Observing the results, we can see that with each level deeper stacks, we see less details of the image.

Results:

Gaussian stack of Lincoln and Gala

Laplacian stack of Lincoln and Gala

Gaussian stack of Frown/Smile Hybrid

Laplacian stack of Frown/Smile Hybrid


Part 1.4: Multiresolution Blending

In this part of the project, we try to blend two images into one by using multi-resolution blending. The idea is that using the gaussian and laplacian stacks we implemented in the previous parts, we compute a gentle seam between the two images seperately at each band of image frequencies, resulting in a much smoother seam.

Results:

Black and White:

Apple


Orange


Mask


Oraple!


Watermelon


Rose


Mask


Rosemelon!


Hermione


Ron


Mask


Face Swap!


Stacks used to create Face Swap:

Laplacian stack of Hermione

Laplacian stack of Ron

Gaussian stack of Mask

Bells and Whistles: Using Colors

Oraple!


Rosemelon!


Face swap!







Part 2: Frequency Domain

Overview:

In this part of the project, we explore gradient-domain processing, specifically how it can be used to fuse and blend images together. The idea behind gradient-domain processing is to create an image by solving for specified pixel intensities and gradients. The specific method we focus on is called Poisson Blending, which makes use of the fact that people usually care more about gradients in an image than the overall intensity. So we can set up the problem as finding values for the target pixels that maximally preserve the gradient of the source region without changing any of the background pixels. Then we can use Ordinary Least Squares to solve the problem.


Part 2.1: Toy Problem

As a warmup, we implement gradient-domain processing to reconstruct a given image. The problem can be described with 3 objectives (v is the target image, s is the source image):

Result:

Toy Story


Toy Story reconstructed



Part 2.2: Poisson Blending

Overview:

To use poisson blending to seamlessly blend together two images, we follow these steps:

  1. First, select source and target regions, align source image with background image, and obtain mask. Ideally, the background of the object in the source region and the surrounding area of the target region should be of similar color.
  2. Solve the blending contraints:
  3. Copy the solved values into the target image. For RGB images, process each channel separately and stack them together to obtain colored result.

Results:

Favourite Result:

Source image


Target image


Naive blending


Poisson blending


Using poisson blending, we can hardly notice any seam at all in the blended image. But this is largely due to the fact that the backgrounds of both images are smooth. The color of the blended region was not changed much either, because the background colors of the two images were also similar. Therefore, the blended result looks very natural. On the other hand, it is clear that if we naively blend the images together by copying the source image region to the target region, we will see very noticeable seams, even if the backgrounds of the two images are similar.

More results:

Deer from Nara


Doe Library Reading Room


Naive blending


Poisson blending


Kyoto Tower


City Night


Naive blending


Poisson blending


Failure Example:

Because the background of the targer region is darker than the source region, the outcome blended region becomes dark and unnatural.

Kyoto


Mt. Fuji


Naive blending


Poisson blending


Bells and Whistles: Mixed Gradient Blending

Mixed gradient blending has the same steps as Poisson blending, but use the gradient in source or target with the larger magnitude as the guide, rather than the source gradient:

Here "d_ij" is the value of the gradient from the source or the target image with larger magnitude, i.e. if abs(s_i-s_j) > abs(t_i-t_j), then d_ij = s_i-s_j; else d_ij = t_i-t_j. Show at least one result of blending using mixed gradients. One possibility is to blend a picture of writing on a plain background onto another image.

Results:

Writing


T-shirt


T-shirt with Writing


Comparison Between 3 Blending Methods:

Input:

Rose


Watermelon


Results:

Multi-resolution blending


Poisson blending


Mixed Gradient blending


In this example, clearly, the most seamless blending is from poisson blending. However, multi-resolution blending preserves the original color of the rose the best. Mixed-gradient blending does not work so well in this case because the background is showing too much.

Another example:

Input:

Ron


Hermione


Results:

Multi-resolution blending


Poisson blending


Mixed Gradient blending


In this example, although multi-resolution blending and poisson blending gave similar results, it appears that multi-resolution blending is most natural. If you look closely, in the result of the poisson blending, the colors of Hermione's eyes are different. Interestingly, mixed gradient blending produced a result where most of Hermione facial features were preserved, but we could still see some traces of Ron on her face.

Generally, when it is important to preserve the color of the source image, or acheive natural colors in the blended area, multi-resolution blending would be a better choice. But because of the potential color difference, multi-resolution blending may result in a gradual but noticeable seam. Poisson blending produces less noticeable seams and thus would be a good choice if color and intensity doesn't matter that much. If we want to keep prominent features on both the source image and the target image, mixed gradient blending is a better choice. However, no matter what blending method we choose, it is important to keep the background texture similar to avoid blurriness or weird colors around the blended region.