CS180 Project 2 - Fun with Filters and Frequencies!

Overview

This project explores how filters and frequencies interact in different and curious ways.

Part 1 Fun with Filters

Math of Gradient Magnitude

To find the magnitude of a gradient, we first find the derivative of the image with respect to x and then the derivative of the image with respect to y. Second, we square both dx and dy and add them together. Finally, we take the L2 norm of this sum. All these calculations are done element by element.

Part 1.1: Finite Difference Operator

In this section, I first convolved a partial derivative filter in the x direction with the cameraman image. Then, I convolved a partial derivative filter in the y direction with the image. Here are the raw and binarize derivatives.

Camera Man X Filter
Camera Man X Filter Binarized
Threshold: 0.25
Camera Man Y Filter
Camera Man Y Filter Binarized
Threshold: 0.2

Here is the gradient magnitude.

Camera Man Gradient Magnitude
Camera Man Gradient Magnitude Binarized
Threshold: 0.2

Part 1.2: Derivative of Gaussian (DoG) Filter

Blurred Finite Difference

After applying the Guassian filter to the camera man image, I discovered that the image was blurred significantly.

Camera Man Gaussian Blurred

With the Gaussian blurred derivative filters in x and y directions, I created another set of image edges. Here are the result. These are a lot smoother than the finite derivative filters. However, the general shape of the edges remain the same.

Camera Man X Finite Blur Filter
Camera Man X Finite Blur Filter Binarized
Threshold: 0.09
Camera Man Y Finite Blur Filter
Camera Man Y Finite Blur Filter Binarized
Threshold: 0.09

Here is the gradient magnitude. With the Gaussain blurring effect, the edges traced by the gradient magnitude are much smoother than using the finite difference operator alone.

Camera Man Finite Blur Gradient Magnitude
Camera Man Finite Blur Gradient Magnitude Binarized
Threshold: 0.15

Derivative of Gaussian

In this section, instead of blurring the original image with a Gaussian filter, we create the derivatives of the Gaussian filter by convolving the Gaussian filter with the Dx and Dy derivatives. Here are the results.

Camera Man X DoG Filter
Camera Man X DoG Filter Binarized
Threshold: 0.09
Camera Man Y DoG Filter
Camera Man Y DoG Filter Binarized
Threshold: 0.09

Here is the gradient magnitude. The result is verys similar to the finite derivative filters' result.

Camera Man DoG Gradient Magnitude
Camera Man DoG Gradient Magnitude Binarized
Threshold: 0.15

Comparison

The edges by blurred finite difference filter and derivatives of Gaussian are very similar besides some differences possibly due to padding and noise. This is expected because convolution should be associative and commutative.

Camera Man Blurred Finite Guassian Gradient Magnitude
Camera Man DoG Gradient Magnitude

Part 2: Fun with Frequencies!

Part 2.1: Image Sharpening

Methods

Blurring

To blur an image, I convolved a 2d Guassian filter with the original image to get the low frequencies.

Sharpening

To sharpen an image, I first blurred an image using the method mentioned above. Then, I substracted the low frequency layer from the original image to get the high frequency layer. Finally, I added the high frequency layer to the blurred image to get the sharpened image. The blurring and sharpening steps can be consolidated into one filter by applying the Gaussian fitler scaled by alpha subtracted from a unit pulse filter scaled by (1 + alpha). This way we can sharpen the image with only 1 filter.

Taj Mahal Results

I used an alpha value of 0.8, a Gaussian sigma value of 5, and filter size of 20 to sharpen the Taj Mahal image. Here is a comparison between the original and the sharpedn image.

Taj Mahal Original
Taj Mahal Sharpened

Blurry Rear View Mirror

This is a blurry photo due to lack of sufficient lighting and unsteady camera. I attempted to sharpen the image. The blurriness was reduced. However, as expected, the shakiness of the photo did not change.

Rear View Mirror Original
Rear View Mirror Sharpened

Blurry City View

Sharpening the image made the watermark background out significantly.

City View Original
City View Sharpened

Blur and Sharpen

In this section, I intentionally blurred a photo of ferns canyon and sharpened it with my sharpening filter. The resharpened image did not come close to the quality of the original image. This might be due to the lossy nature of the Gaussian blur. In other words, sharpening a Gaussian blurred image cannot restore all high frequency information lost through the blurring process.

Fern Canyon Original
Fern Canyon Blurred
Ferns Canyon Sharpened

Part 2.2

Methods

In this section, I created a hybrid image by stitching together the low frequency layer of one image with the high frequency layer of another. I extracted low frequency layer through a Gaussian filter and high frequency layer through a Laplacian filter. My three attempts at creating hybrid images are listed below.

Sour and Guts

Here I created a hybrid image of Olivia Rodrigo in her Sour and Guts eras. I took the low frequency from her Guts photoshoot and overlayed the high frequency from her Sour photoshoot on top. Up close, you can see the Sour era image and the Guts era image when you are far away.

Sour Original (Sigma = 9, Filter Size = 30)
Guts Original (Sigma = 30, Filter Size = 40)
Combined Hybrid Image

Below are the Fourier domain frequencies.

Sour Original Fourier frequencies
Guts Original Fourier frequencies
Sour high frequency Fourier frequencies
Guts low frequency Fourier frequencies
Hybrid image Fourier frequencies

Rainbow or Brown?

Here, I created a hybrid image between a rainbow trout and a brown trout. The low frequency layer came from the rainbow trout image, so you can see the rainbow trout from afar. You can see the brown trout when you are up close as the high frequencies came from the brown trout image.

Rainbow Trout Original (Sigma = 7, Filter Size = 20)
Brown Trout Original (Sigma = 20, Filter Size = 20)
Combined Hybrid Image

Elks! (Failed)

Here, I attempted to create a hybrid between two elk photos taken at different time. In one photo, the elks are head bumping one another, whiel in the other photo, one the elks raises its head. No matter which picture acted as the low frequency layer, the high frequency layer always disappeared. When I tried to blur the low frequency layer further, the background low frequency layer became too blurred to be recognized. This was probability because the identification of elks required a lot of high frequency information, thus the low frequency layer cannot be blurred too much. However, once this the high frequency of the low frequency layer is retained, the high frequency layer had too much overlap with the low frequency layer thus disappearing from the hybrid result.

Elks Fighting 1 Original (Sigma = 1, Filter Size = 20)
Elks Fighting 2 Original (Sigma = 2, Filter Size = 20)
Combined Hybrid Image

Multi-resolution Blending and the Oraple journey

Part 2.3: Gaussian and Laplacian Stacks

Here are some select Laplacian stack images for the apple and the orange.

Apple (1)
Orange (1)
Apple (2)
Orange (2)
Apple (11)
Orange (11)

Here is the result for blended orapple image.

Apple Stack
Orange Stack
Combined Stack

Part 2.4: Multiresolution Blending (a.k.a. the oraple!)


Methods

I first created Laplacian stacks for the first image, the second image, and the filter mask. Then at each layer of the stack, I convolved each mask with both images to create two intermediate results. Then, I computed the average of the two masked images and collapsed the Laplacian stack to reveal the final result. Blending layer by layer smoothes out the connection between two images, allowing for an elegant transition from one image to another.

Orapple

Apple
Orange
Combined Orapple

Thunder Storm at Eel River?

I changed the serene evening sky of the eel river into show of lightning.

Eel River Original
Lightning Original
Blended Eel River and Lightning

Golden or Rainbow?

I blended together 3/4 of a golden trout and 1/4 of a rainbow trout together.

Golden Trout Original
Rainbow Trout Original
Blended Golden and Rainbow Trout
Laplacian Stack
Apple
Orange
Combined Orapple

Bells and Whistles

Color Enhanced Images

I explored an additional three combinations of color vs gray image hybridizations. Here, I will present the hybridization with gray image 1, color image 2; color image 1, color image 2; and color image 1, gray image 2.

Colored sour colored Guts (1)
Colored sour gray Guts (2)
Gray sour colored Guts (3)
Gray sour gray Guts (4)

Image (1) and (3) are pretty similar because the purple color of the low frequency is very overpowering, so it draws attention to the low frequency at short and long distances. Thus, the hybrid effects in (1) and (3) are not very good. Comparing (2) and (4), we can see that the all gray scale hybrid image's Sour era details are too faint to be eye-catching at close range. Since the major details that signify the Sour era are the colored stickers, allowing the Sour's high frequency color to come through (2) is significantly better than the all gray scale hybridization. Therefore, I think image (2) is the best hybrid image out of the four.

Colored Blending Images

I have used color for blending the orange and the apple, golden trout and rainbow trout, and eel river and lightning. It has enhanced the appearance of the resulting images.

Final Reflection

I really enjoyed this project! I learned that frequencies, when manipulated correctly, can produce very interesting results.