CS 194-26: Project 2

Image Manipulation with Filters & Frequencies

Emily Ma


Summary: In this project, I learned a lot about image manipulation using different filters and frequencies. Throughout the parts of the project, I demonstrate how to blur an image using a Gaussian kernel to filter, find the edges of an image, sharpen images, create hybrid images, and smoothly blend images. The most important takeaways I learned was how filters can affect the frequency of images and how important it is to merge images by similar structures in the images, such as facial features or geometric shape.

Part 1: Fun with Filters

Part 1.1: Finite Difference Operator

In this part, I calculate the edge gradient magnitude of the cameraman.jpg image by using the finite difference operators Dx and Dy. Dx is just [[1, -1]] and Dy is the transpose of Dx. Below I show the results of the image after convolving the image with each Dx or Dy to result in the partial derivatives of the image with respect to x (df/dx) or y (df/dy). To calculate the edge gradient magnitude, this is just the squareroot of the sum of df/dx squared and df/dy squared as the gradient is the vector of the partial derivatives, so the magnitude of the gradient vector is calculated the same as any other vector. To alleviate some of the noise in the edge image, I binarized the image using a threshold value of 0.15, so any pixels in the image with a greater value would become 1 (white) and any lower values would become 0 (black).


Image Convolved with Dx
Image Convolved with Dy

Gradient Edge Magnitude
Binarized Gradient Edge Magnitude

Part 1.2: Derivative of Gaussian (DoG) Filter

Continuing off of part 1.1, I tried creating a gradient edge magnitude of the cameraman, but this time by first convolving with a Gaussian filter to blur the image slightly. I then repeated the process of convolving with Dx and Dy, calculating the edge gradient, and binarizing the image. I found that overall this looked better than part 1.1. By using the Gaussian filter first, I was able to reduce the noise of the image, so that when I binarized the image, all of this noise disappeared cleanly. The outline is also more continuous rather than blocky from part 1.1. The edge image was not as bright as part 1.1 though this was the same after binarizing. I also tried convolving the Gaussian filter with Dx and Dy, and was able to reduce the total amount of convolutions of the image. Overall, the images from either applying Dx, Dy to the image or the Gaussian filter look visually the same, which matches what I would expect since convolutions are associative.


Image with Gaussian Filter
Gaussian Image Convolved with Dx
Gaussian Image Convolved with Dy

Gaussian Image Gradient Edge Magnitude
Gaussian Image Binarized Gradient Edge Magnitude

DoG Gradient Edge Magnitude
DoG Binarized Gradient Edge Magnitude

Part 2: Fun with Frequencies

Part 2.1: Image Sharpening

For this part, I used an unsharp mask filter to sharpen some images. To sharpen an image, you subtract the Gaussian convolution of the image in order to get the higher frequencies of the image and then add alpha times these higher frequencies to the image to increase the high frequencies. Here, alpha is the sharpening factor—higher alpha is a sharper image. I combined this into one convolution filter by convolving the image f with ((1 + alpha)e - alpha * g) where e is the unit impulse filter and g is the Gaussian filter. The results of the Taj Mahal are below.

I also sharpened my own images. For the bunny image, I first blurred the image by using a Gaussian filter and then used my unsharp mask filter. The image did not sharpen back to its original form as it and seems to have also increased the contrast when increasing the sharpness. Overall, these results are poor compared to just sharpening the original image.


Original Image
Sharpened alpha = 1
Sharpened alpha = 3

Original Image
Sharpened alpha = 1
Sharpened alpha = 2

Original Image
Blurred Image
Sharpened alpha = 5


Part 2.2: Hybrid Images

I created hybrid images by manipulating the frequencies of the two images. For one image, I apply a low pass filter by applying a Gaussian filter to blur the image. The other image I apply a high pass filter by subtracting the Gaussian blurred image from the original. The low frequency image looks a bit blurry and the high frequency image is the sharper parts of the image. Below I apply this method to multiple images starting with the given Derek and Nutmeg images. Next, I attempted to create a hybrid image of baby Yoda older Yoda. This result ended up failing since even though the images are of the same type of Yoda, the baby Yoda has a much smaller face shape. So although the eyes are aligned, the rest of the images are misaligned, and you can see weird overlap of the top of their heads and ears. For another example, I created a hybrid image of Drake and Kanye. This result turned out a lot better as Drake and Kanye have similar facial structures.

Derek Image
Nutmeg Image
Hybrid Derek Nutmeg Image

Baby Yoda Image
Old Yoda Image
Hybrid Baby Old Yoda Image
Drake Image
Drake FFT
Kanye Image
Kanye FFT

Drake Low Frequency
Drake Low FFT
Kanye High Frequency
Kanye High FFT

Drake Kanye Hybrid
Drake Kanye FFT


Part 2.3: Gaussian and Laplacian Stacks

In this part, I blended the apple and orange together using a vertical mask and multiresolution blending. I first created a Gaussian stack of both input images and the mask image by convolving by a Gaussian filter at each level. Then, I created a Laplacian stack by subtracting two consecutive Gaussian stack images. The final image in the Laplacian stack would just be the last Gaussian image. I then combined the images by adding up all of the images in each Laplacian stack and weighing the Laplacian images by multiplying the Gaussian mask and 1 - Gaussian mask at each level to get the final result. Below, I recreate the images from the paper at Laplacian levels 0, 2, and 4 to get the final image in the bottom right corner.






Part 2.4: Multi-Resolution Blending

I used the multiresolution technique for blending on a few of my own images. For my friend and the Sun blend, I used an irregular mask in a circular shape as seen in the Laplacian stacks.