Project 2: Fun with Filters and Frequencies

Nicholas Ha

Part 1: Fun with Filters

1.1 Finite Difference Operator

First, I convolved the cameraman.jpg image with the finite difference filters Dx = [1, -1] (row) and Dy = [1, -1] (column) in order to find the partial x and y derivatives.

Next, I computed the gradient magnitude of the image by summing the squared partial derivatives Dx and Dy and then taking the square root.

Finally to create an edge image, I binarized the gradient magnitude image by selecting a threshold for which where values are greater than or equal to the threshold, we set it equal to 1 and otherwise we set the value equal to 0.

missing
Dx
missing
Dy
missing
Gradient Magnitude
missing
Edge Image, Binarized Gradient Magnitude

1.2 Derivative of Gaussian (DoG) Filter

To create a 2 dimensional Gaussian filter, I used the function cv2.getGaussianKernel() to create two 1 dimensional kernels and took the outer product.

I then convolved the cameraman image with this 2D Gaussian filter and repeated the steps outlined in part 1.1 to create another gradient magnitude image and binarized edge image.

missing
Blurred Image
missing
Gradient Magnitude of Blurred Image
missing
Edge Image, Binarized Gradient Magnitude of Blurred Image

What differences do you see?

This method of using a Gaussian filter first yields a clearer image with less noise.

Using a Single Convolution

Another method that I tried was to create a derivative of gaussian filters and convolve the Gaussian filters with Dx and Dy. Then I convolve the cameraman image with this DoG filter. It turns out that we get the same result as before!

missing
Gaussian Filter Convolved with Dx
missing
Gaussian Filter Convolved with Dy
missing
Gradient Magnitude
missing
Edge Image, Binarized Gradient Magnitude

Part 2: Fun with Frequencies

2.1 Image Sharpening

To get a sharper image, I first blur the image and convolve it with a Gaussian filter. To isolate only the high frequencies in the photo, I then subtract the blurred image from the original image. Finally, I add the high frequencies to the original images to enhance them and get the sharpened image. The sharpened image contains more detail than the original image.

missing
Taj
missing
Blurred Taj
missing
Sharpened Taj
missing
NYC
missing
Blurred NYC
missing
Sharpened NYC
missing
Lizard
missing
Blurred Lizard
missing
Sharpened Lizard

2.2 Hybrid Images

To create a hybrid image of two images, I combine the high frequencies of one image with the low frequencies of the other. I get the low frequencies by blurring the image with a Gaussian filter. I get the high frequencies by subtracting the low frequencies from the original image.

missing
Derek
missing
Nutmeg
missing
Hybrid Derek + Nutmeg
missing
Hybrid Derek + Nutmeg (Colorized)
missing
Tim
missing
Pot of Greed
missing
Hybrid Tim + Pot of Greed
missing
Jasper
missing
Esam
missing
Hybrid Jasper + Esam
missing
Jasper FFT
missing
Esam FFT
missing
High-Pass Jasper FFT
missing
Low-Pass Esam FFT
missing
Hybrid Jasper Esam FFT

Failure Case:

missing
Matt Damon
missing
Mark Wahlberg
missing
Hybrid Wahlberg + Damon

I attempted to make a hybrid image of Mark Wahlberg and Matt Damon. However, the picture of Matt Damon seems to be much concentrated and we can't really see any detailed features of Mark Wahlberg that well.

Bells and Whistles:

I incorporated color into my hybrid images to enhance the effect. To accomplish this, I applied the method above of combining low frequencies and high frequencies of each image to all 3 color channels. For the images I used, it seemed to work better to use color for both low frequency and high frequency components.

2.3 Gaussian and Laplacian Stacks

To create the Gaussian stack, I convolved the original image with a Gaussian and kept convolving for each level. To create the Laplacian stack, for each level, I took the difference between images in same level of the Gaussian stack and the previous level of the Gaussian stack.

Apple Gaussian Stack Images:
missing missing missing missing missing
Orange Gaussian Stack Images:
missing missing missing missing missing
Apple Laplacian Stack Images:
missing missing missing missing missing
Orange Laplacian Stack Images:
missing missing missing missing missing

2.4 Multiresolution Blending

To blend two images, I create a mask, a Gaussian stack of the mask, a Laplacian stack of the first image, and a Laplacian stack of the second image. Then, I combine the Laplacian stacks with weights from the mask's Gaussian stacks.

Oraple Mask
missing
missing missing missing missing missing
missing missing missing missing missing
missing missing missing missing missing

More Examples:

# 1 Blending a daytime background with a night time background

Mask
missing
missing missing missing

# 1 Blending a doorway with a nebula background.

Mask
missing
missing missing missing
Blended Nebula Door Laplacian Stacks
missing missing missing missing missing missing missing missing missing missing