Fun with Filters and Frequencies!

Katherine Wu

Part 1.1: Finite Difference Operator

Partial derivatives: I calculated the partial derivative with respect to x by using signal.convolve2d and convolving the cameraman image with [1,-1]. I calculated the partial derivative with respect to y in a similar way, but by convolving with [[1],[-1]].

Gradient magnitude: I calculated the gradient magnitude using sqrt(dx**2 + dy**2), where dx and dy are the partial derivative images for x and y.

cameraman
Original
D_x
Partial Derivative in x
D_y
Partial Derivative in y
gradient magnitude
Gradient Magnitude
Edge Image with Threshold 0.18


Part 1.2: Derivative of Gaussian (DoG) Filter

After applying the Gaussian filter, there is less noise in the image and the edges of the gradient image are a lot smoother. You can see this with the grainy white specks near the bottom of the original image that are no longer present in the gaussian blurred filter image. You can also see that the edges are more defined, especially for the camera and the outline of the head.

The output with the Gaussian filter:

Blurred partial derivative in x
Blurred partial derivative in y
Blurred Gradient Magnitude, Threshold 0.18

I also used a single convolution instead of two by creating DoG filters for dx and dy. The resulting DoG gradient magnitude edge image is the nearly the same as before.

DoG Partial Derivative in x
DoG Partial Derivative in y
DoG Gradient Magnitude, Threshold 0.18


Part 2.1: Image "Sharpening"

Using the unsharp masking technique, I first get the high frequencies of the image by subtracting the gaussian blurred version of the image from the original image. Then I add a little bit of these high frequences back into the original image to obtain the sharpened version. Below is the technique used on the taj image and the NYC skyline.

taj
Original Taj
taj_blurred
Blurred Taj
high_freq_taj
High Freq Taj
Sharpened Taj
Original NYC
Blurred NYC
High Freq NYC
Sharpened NYC

For evaluation, I chose this image of a sharp hawk and blurred the image. When I resharpened the image, it was sharper compared to the blurred image but still not as sharp as the original sharp hawk image. From far away the original and resharpened images are similar, but you can see that some of the details from the original image are lost (ie the feather, beak, pupil detail) with the resharpened image. Thus, we see that the unsharp masking technique cannot perfectly reverse a blurred image back into a sharp image.

Original Hawk
Blurred Hawk
Blurred and Resharpened Hawk


Part 2.2: Hybrid Images

In this part, I low pass filter one image and high pass filter the second image, and then add the two images together to form a hybrid image. The low-pass filter is the standard 2D gaussian filter, and the high-pass filter is original image minus the gaussian filtered image.

Hillary Clinton
Donald Trump
Trump Clinton Hybrid

Frequency analysis of the Trump Clinton result (log magnitude of Fourier transform):

Clinton FFT
Trump FFT
Filtered Clinton FFT
Filtered Trump FFT
Trump Clinton Hybrid FFT

More examples (Obama and Bush, Owl and Eevee, Dog and Cat):

Failed Example: I attempted blending this parrot and Taylor Swift together, but it did not work out because the faces were at different angles, and the parrot had a much longer beak than Taylor's nose. The head shapes were also too different for the blending to look smooth; the parrot has a much smaller and less round head. Also, both of Taylor's eyes were in the picture, whereas only one of the parrot's eyes was in the picture.



Part 2.3: Gaussian and Laplacian Stacks

Below is the laplacian stack for the left half of the apple and right half of the orange, as well as the final blended oraple in color.



Part 2.4: Multiresolution Blending

Regular masking:

Laplacian stack for fire and water images:

Irregular masking:

Laplacian stack for flower and galaxy images:



Reflection

The most interesting thing I learned from this project was how convoluting with a Gaussian could be used in many different image processing contexts— blurring an image, sharpening an image, getting low/high frequencies, etc. I also thought it was very cool that we could combine the low and high frequencies of an image in such a way that we see different images from up close and from far away— human eye perception is weird.