CS 194-26: Project 2

Vinay Chadalavada

Fun With Filters

Part 1.1: Finite Difference Operator

In this part, we ran a derivative filter on cameraman.png. We had the run the filters comparing pixels both horizontally and vertically to get the rate of change in both directions.

To compute the gradient magnitude I just did (X_gradient^2 + Y_gradient^2)^0.5. I then binarized it to get rid of the noise.

The first image is the Y gradient and the second image is the X gradient.

The first image is just the raw gradient magnitude computed from the X and Y gradient and the second image is the gradient magnitude binarized at a threshold of 0.3.

Part 1.2: Derivative of Gaussian (DoG) Filter

We can also use a 2D Gaussian to blur the image to get better edges. When we do this the edges detected are much smoother compared to our first attempt as we can remove some of the rate of change produced by camera noise in the picture with the Gaussian. In addition, with the commutative property of convolutions, we can convolve the derivative filters with the Gaussian first to produce a filter so we only need to convolve with the image once. As shown below the same gradient magnitude will be produced.

The first image is the edges produced when we convolve the image with the Gaussian and then the derivative filters and the second image is the edges found when we convolve the Gaussian first with the derivative filters and then convolve with the image in a single convolution. As you can see they are very similar.

Part 2: Fun with Frequencies!

Part 2.1: Image "Sharpening"

We can sharpen images by finding the high frequencies of an image and then adding them into the original image. To find the high frequencies we can just subtract a Gaussian blurred image from the original. This can also be simplified into a single convolution: Convolve(Original Image, (1 + alpha) * unitImpulse - alpha * Gaussian. The alpha variable is how much of the high frequencies you want to add while the unitImpulse is just the filter that when convolved with an image just returns the same image back.

This is the original blurry image of the Taj Mahal.

The images above are all sharpened by a different alpha (1,3,5,7 respectively). In my opinion, the third image, where alpha is 5, looks the best.

The first image is the original image of a macaw and the second image is a blurred version of it. By using the sharpen filter we can try to get the blurred image to look more like the original

The images above are all sharpened by a different alpha (1,5,10,15 respectively). In my opinion, the fourth image, where alpha is 15, looks the closest to the original. When alpha is 15, it seems like the colors on the back of the macaw are sharper than the blurred image and the eye of the macaw is closer to the original.

Part 2.2: Hybrid Images

In this section we will be making hybrid images. The process involves aligning the two images, applying a Gaussian filter to get the low frequencies of one image, applying a high pass filter (subtract blurred from original), and then taking the average of both images. When looking close up the high frequency image will be more visible and when zoomed out the low frequency image will be more visible.

Merging Lion With Tiger

These are the original images. The lion will be used as the high frequency image and the tiger will be used as the low frequency image.

These are the fourier transforms of the original images. The first one represents the lion and the second one represents the tiger.

These are the images after the filters are applied. The high frequencies are extracted from the lion and the low frequencies are extracted from the tiger.

These are the fourier transforms of the images after their respective filters have been applied. The first one represents the lion after the high pass filter as the center of the graph has been dimmed indicating the lowest frequencies are gone. The second image represents the tiger after the low pass filter has been applied as many of the values further away from the origin have dimmed or become 0.

The first image is the resulting hybrid image. Up close it shows a lion and further away it shows the tiger. The second image is the resulting Fourier Transform of the hybrid image. It would have been even better if the noses lined up.

Merging Cat With A Dog

Merging Eagle With Modern Day George Washington

This one didn't turn out amazing, but I found it really funny how well their noses match. I think the main issue was the eagle's head was much smaller than George Washington's head, so even if you align by the eyes their faces don't overlap very well.

Part 2.3: Gaussian and Laplacian Stacks

In order to merge images together, we first need to implement Gaussian and Laplacian stacks. To implement Gaussian stacks we can repeatedly blur with an image with a Gaussian. I doubled sigma every time to make the stack steeper. To implement Laplacian stacks we can subtract neighboring Gaussian stacks and the last Gaussian stack level will correspond to the last Laplacian stack levels.

Laplacian Stack Level 0 Blend

Laplacian Stack Level 2 Blend

Laplacian Stack Level 4 Blend

Full Blend

The images above replicate Figure 3.42 and show the process of blending an image. We create a Laplacian stack for both images and create a Gaussian stack for a simple half white/half black mask. To merge each layer together we use the formula for each level: Mask(x,y) * LeftLaplaseStack(x,y) + (1- Mask(x,y)) * RightLaplaseStack(x,y). The last image is the full blended Orapple!

Part 2.4: Multiresolution Blending

We can use the techniques we learned in 2.3 to blend a variety of images and changing the masks will lead to different sorts of blends

The Orapple From The Last Section!

Here I blended a picture of a river and a volcanic picture together. Unlike the orapple example, here the mask merged the top of one image with the bottom of another.

Here I blended a picture of my hand with a cat eye. This required me to use an irregularly shaped mask.

Acknowledgements

Websites Where Some of My Images Came From

George Washington (2.2)
Eagle (2.2)
Cat (2.2)
Dog (2.2)
Tiger (2.2)
Lion (2.2)
Volcano (2.4)
River (2.4)
Cat (2.4)