CS 194-26: Project 2

By Prangan Tooteja

Part 1- Fun with Filters

1.1 - Finite Difference Operator

The goal of this task was to detect edges from the following image

Original Image

In this part of the project we computed the derivative of the image by convolving gradient vectors Dx = [1, -1] and Dy = [1, -1]T. Similar to the idea behind a gradient on a plane, this returns the difference between adjacent points. We constructed edges as being the vectors formed by x and y derivatives and computed the gradient magnitude, M as being magnitude of the vector formed by dx and dy of the image. That is M = √(dx2 + dy2) The threshold used for the following gradient magnitude is the 89th percentile or 0.0745.

dx
dy
Gradient Magnitude
Binarized Gradient Magnitude

1.2 - Derivative of Gaussian Filter

As seen in the edge image above, while the derivatives of the raw image do a remarkable job in detecting the edges, they also detect a lot of the noise in the image (see the man's face and grass). One way to reduce this noise is to blur the image before detecting edges. Shown below are the images from above after preprocessing the original image with a convolution with a gaussian.

dx
dy
Blurred Gradient Magnitude
Blurred Binarized Gradient Magnitude

Blurring before detecting edges reduced a lot of the noise and made the edges significantly stronger. A benefit of convolution is its commutative property, so we can take the partial derivative of our gaussian before convolving with the image to get the same result. As can be seen below, the result after this operation is the same as the previous result.

Derivative of Gaussian

Part 2 - Fun with Frequencies

2.1 - Image Sharpening

The goal of this task was to sharpen blurry images. We did this by subtracting the lower frequencies in the image from the original image through the operation sharpened_image = (1 + α) blurry_image - α * blurry_image * gaussian. This is the same as convolving the blurry_image with ((1 + α) * unit_impulse - α * gaussian) Here are the results for several pairs of images.
As can be seen, for α=1, 2 the edges are sharper and as we increase α to 10, we start seeing some distortion in the image edges.

Blurry Image
Sharpened Image α = 1
Sharpened Image α = 2
Sharpened Image α = 10
Blurry Image
Sharpened Image α = 1
Sharpened Image α = 2
Sharpened Image α = 10
Blurry Image
Sharpened Image α = 1
Sharpened Image α = 2
Sharpened Image α = 10
Blurry Image
Sharpened Image α = 1
Sharpened Image α = 2
Sharpened Image α = 10

This is the sample output for the unsharp filter mask after applying it to blurred version of an originally sharp image of a train

Original Image
Blurred Image
Sharpened Image α = 1
Sharpened Image α = 2
Sharpened Image α = 10

2.2 - Hybrid Images

For this part we created hybrid images by aligning two images. Then, we ran one of them through a high pass filter and the other through a low pass before averaging them . This produced the results below where the image with the high pass filter can be seen from close to the image, and the image with the low pass filter can be seen from far away from the image. The smiling image did not work so well because the images were really close to each other and the faded lips are still prominent in the blown up picture.

High Pass Image
Lowpass Image
Blown Up Hybrid Image
Zoomed Out Hybrid Image
High Pass Image
Lowpass Image
Blown Up Hybrid Image
Zoomed Out Hybrid Image
High Pass Image
Lowpass Image
Blown Up Hybrid Image
Zoomed Out Hybrid Image

FFT for favorite image

As can be seen in the image, there is a strong vertical line in the FFT, which probably comes from the vertical structure in the hair of the lion and tiger.

2.3 - Gaussian and Laplacian Stacks

In this section we used Gaussian and Laplacian stacks to eventually create hybrid images. Gaussian stacks are sort of similar to the pyramids we implemented last project, with the exception that we do not reduce the image resolution as we go deeper into the stack. However, the idea is largely similar, we have a function that we apply to the image at each level of the stack, which in this case is a Gaussian, resulting in an increasingly blurred image as we traverse down the stack. The Laplacian stack can be constructed from a gaussian stack by taking the differences between two layers of the gaussian stack. The deepest layer of the laplacian stack is equal to the deepest layer of the gaussian stack. Intuitively, each layer can be thought of as the frequencies between each layer of the gaussian stack, allowing us to partition frequencies into bands.

Gaussian
Gaussian
Laplacian
Gaussian
Laplacian
Orapple Weighted Laplacian

2.4 - Multiresolution Blending

Using the features we created above, we can merge multiple pictures, using a mask where the mask is 0 where we want one image and 1 where we want the other. Below are some examples of images I created using the feature.

Image 1
Image 2
Mask
Result
Image 1
Image 2
Mask
Result
Image 1
Image 2
Mask
Result

Bells and Whistles

For bells and whistles I colorized both the hybrid images and merged images

Hybrid Image
Blended Image
Blended Image