CS180 Project 2: Nathalys Pham

Overview

In this project, we use filters and frequencies to do a variety of things such as finding edges, sharpening images, making hybrid images, and blending images.

Part 1: Fun with Filters

Part 1.1: Finite Difference Operator

I found partial derivatives by convolving the image with Dx = [1 -1] and Dy = [1 -1]T. I used scipy.signal.convolve2d with mode='same' for the convolution. Then, I found the gradient magnitude by doing sqrt((df/dx)^2 + (df/dy)^2). I finally binarized the gradient magnitude, and I picked a threshold that showed as much of the man and as little of the noise as possible.

partial derivative dy partial derivative dx gradient magnitude binarized

Part 1.2: Finite Difference Operator

I applied the Gaussian filter using cv2.getGaussianKernel to blur the image before finding the partial derivative and gradient magnitude. The result is smoother and cleaner edges. The edges are also a lot thicker even though I only used a sigma value of 1. More edges of the man, camera, and background show up, and less noise shows up.

gaussian partial derivative dy gaussian partial derivative dx gaussian gradient magnitude gaussian binarized

Instead of convolving twice, I took the derivative of the gaussian filters before applying to the image to create a derivative of gaussian filter (DoG). The result is basically the same as applying the gaussian filter and derivatives separately, except for a few dots of noise that are different.

DoG partial derivative dy DoG partial derivative dx DoG gradient magnitude DoG binarized

Part 2

Part 2.1

To sharpen the image, I applied the gaussian filter using cv2.getGaussianKernel to the image to get the low frequencies, and then I subtracted the low frequencies from the original image to get the high frequenices. I then multiplied the high frequencies by a value alpha and added it back to the original image. The sharpened image is calculated with the unsharp mask filter, im + alpha * (im - blurred).

original image low frequencies high frequencies
original image low frequencies high frequencies
alpha = 0 (og) alpha = 1 alpha = 3 alpha = 5 alpha = 20
alpha = 0 (og) alpha = 1 alpha = 3 alpha = 5 alpha = 20

I attempted to blur a sharp image and then sharpen it. It is difficult to tell from the below pictures, but the resulting image was not as good of quality as the original image no matter how much I changed alpha.

original image blurred image sharpened blurred image

Part 2.2

To make hybrid images, I combined the high frequencies of one image with the low frequencies of another. the result is that you predominantly see the high frequencies close up but predominantly see the low frequencies from further back. I also used color to enhance to effect. I used the colors of both images. The subtle high frequency color with the high frequency lines add extra detail close up, but the color of the low frequency image blurred added to the effect of the low frequency image.

original original aligned aligned low frequency low frequency
high frequency high frequency high nutmeg + low derek high derek + low nutmeg

Results

I like the results of this one especially around the face.

2D nathalys 3D nathalys 2.5D nathalys

I think this was my best result.

happy sad sappy

These results were scary, but I think it's pretty funny and interesting to look at.

monkey muadh muadhkey

Frequency Analysis with Fourier Transform

monkey fft muadh fft monkey high frequencies fft muadh high frequencies fft
monkey low frequencies fft muadh low frequencies fft monkey high and muadh low fft muadh high and monkey low fft

Failure

The below hybrid image was a failure and looks really weird. I still think it is funny though especially around Totoro's eyes. This one failed because Totoro's face is a lot shorter than Jenny's, so the alignment just didn't work well.

jenny totoro jotoro

Part 2.3

To blend, I used Laplacian stacks for the images and a Gaussian stack for the blended region. In the Gaussian stack, the Gaussian filter is applied to the image another time at each successive layer, and this makes the seams more blended at lower frequencies. The Laplacian stack has the sub-band images between each layer of the Gaussian stack. The images become more blurred as the mask becomes more blurred. This results in a clean blend because the two images are very blended together at lower frequencies but still maintain their lines and detail.

Level 0

Level 1

Level 2

Level 3

Level 4

Level 5

Level 6

Levels combined

Part 2.4

I blended the images together by multiplying the Laplacian of image 1 at a certain layer with the Gaussian of the mask at that layer, and I added that to Laplacian of image 2 at that layer with 1 - the Gaussian of the mask at that layer (G * L1 + (1 - G) * L2). For the result with the completed blend, I added the blend at every layer together. I also used color to better the effect, and I did this by picking images and objects that had similar hues and values. This makes the images blend better and makes the resulting image more convincing and interesting.

apple orange mask orapple blend
chihuahua muffin mask chihmuffin blend
gudetama carbonara mask gudenara blend

Failure

This one didn't turn out well because diglett's sides and top are transparent, but its bottom is not blended enough into the man. All edges of diglett are blended by the same sigma, so some regions are blended too much and some too little.

diglett muscle mask muslett blend

Conclusion

I learned a lot about frequencies from this project, and it's cool how I can so much with image processing by just messing around with frequencies. We did so much like edge detection, sharpening, and blending just by blurring images and using math. This project also made filtering and FFT more intuitive for me. My favorite part was blending because the method was simple yet effective. I also liked this project because I got to make a lot of weird images and share them with my friends :].