CS 194-26 Project 2

Fun with Filters and Frequencies!

Angela Xu


Overview

In this project, we played with filters and frequencies to manipulate images. We used various techniques to blur and sharpen images, and also created some cool hybrid and blended images!

Part 1: Fun with Filters

Finite Difference Operator

For this part, we first used finite differences to filter in x and y directions. We then used these partial derivative images to compute the gradient magnitude and edge images.

cameraman cameraman_x cameraman_y cameraman_grad cameraman_edge

To compute the gradient magnitude, we first find the partial derivatives of both X and Y directions by convolving the image with finite difference operators.
We then find the magnitude of the gradient from the partial derivatives. The equation looks something like this:

sqrt(d_x^2 + d_y^2).

Additionally, to find the edge image, we use a threshold of 0.3 to binarize the gradient magnitude image. This means we assign white or black pixel values
depending on if they fall above or below the thresholds.

Derivative of Gaussian (DoG) Filter

The first edge image we created had some noise, so we use a 2D Gaussian kernal to do some blurring. This can be done with 2 methods, which are shown below:

Method 1
We apply the Gaussian filter to the image, then calculate the X and Y partial derivatives.

blurred blurred_x blurred_y blurred_grad blurred_edge

Method 2
We calculate the X and Y partial derivatives of the Gaussian and then apply them to the original image, essentially letting us convolve with the image only once.

g_x g_y gaus_x gaus_y gaus_grad gaus_edge

As we can see, both methods produce very similar results!
The difference in using the DoG filter is that the edges have smoother, more prominent lines, and there is less noise compared to before.


Part 2: Fun with Frequencies

Image "Sharpening"

Now we want to try sharpening some images! Using the same Gaussian filter, we can find the high frequencies of an image by subtracting the low frequencies (the blurred image).
Then, we can add these high frequencies to the image to increase sharpness! Here are 3 examples:

Taj

taj taj_low taj_high taj_sharp

We are able to combine this process into a single convolution operation called the unsharp mask filter, the equation is (1+alpha) * Unit Impulse Filter - alpha * Low Pass Filter.

Taj Using Unsharp Mask

taj taj_unsharpmask

Billy Bob (my hamster) Using Unsharp Mask

bb bb_unsharpmask

Finally, we tried blurring and then sharpening some flowers!

flwrs blurry_flwrs flwrs_unsharpmask

The final image isn't as nice as the original, but the details are still brought out of the blurry.

Hybrid Images

Time to make some cool hybrid images! By combining low frequencies of one image with the high frequencies of another, we can create
an optical illusion, tricking the mind to see one thing from a distance and something different up close. We do this by choosing
two images, aligning them, finding the high/low frequencies, and then averaging the two together.
As we'll see in one of the examples, this doesn't ~always~ work well.

Yoshi + Koopa = Yoopa

yoshi koopa yoopa

Kirby + Jiggly Puff = Kirbly...ish

kirby jiggly kirbly

This was a failure. Although the circular bodies lined up nicely, Kirby and Jiggly's facial features are positioned at very different places.
With pink skin and blue eyes being quite contrasting colors, this made it difficult to blend (you can clearly still see both).

Bert + Pineapple Under the Sea = Bert Under the Sea

bert pineapple bertapple

We can see the log magnitude of Fourier transform of Bert Under the Sea images here:

fbertbertfpine pineapple fhbert high freq Bert flpine low freq pineapple fbertapple bertapple

Multi-resolution Blending and the Oraple journey

Now we will be doing some multiresolution blending using Gaussian and Laplacian Stacks.

Gaussian and Laplacian Stacks

We start with 2 images and a mask. We make 5 layers of Gaussian stacks by convolving a Gaussian over and over. We make
5 layers of Laplacian stacks by subtracting each Gaussian layer by the layer that follows it, with the final Laplacian
being equal to the final Gaussian. The process is illustrated below with the apple and orange!

lapple0 lorange0 half0
lapple2 lorange2 half2
lapple4 lorange4 half4
happle horange oraple

Yay...an oraple!

Multiresolution Blending

Here are some more examples, using different images and masks. Very fun!

Goomba + Cupcake = Goomcake

lgoom0 lcupcake0 halfgoom0
lgoom2 lcupcake2 halfgoom2
lgoom4 lcupcake4 halfgoom4
hgoom hcupcake goomcake

Bunny + Bread = Bunbread

lbun0 lbread0 halfb0
lbun2 lbread2 halfb2
lbun4 lbread4 halfb4
hbun hbread bunbread

Conclusion

I learned a lot from this project and really enjoyed making my own creations! This
project involved a lot of experimentation, from testing different Gaussian kernals
and thresholds to utilizing different methods of convolving and combining filters and
frequencies. Overall, it was very cool to be able to implement common features such as
layer masks and blending. I now have a deeper understanding of how these popular
photo-editing functions work! :D