CS 180 Project 2 - Geoffrey Xiang

Part 1: Fun with Filters!

Part 1.1: Finite Difference Operator

I convolved the original image using the finite difference operators Dx = [1, -1] and Dy = [1, -1].T. Then, by using Euclidean Distance from (0, 0) to represent the magnitude for each pixel (essentially sqrt((df/dx)^2+(df/dy)^2)), I used the resulting images from the convolutions with Dx and Dy to create an edge image. After playing with the threshold values, I found that 0.3 worked very well in defining the edges of the image.

Original cameraman.png
x direction (Dx) filter
y direction (Dy) filter
Edge image with 0.3 threshold

Part 1.2: Derivative of Gaussian (DoG) Filter

To improve upon edge detection with the finite difference operators, I convolved the image with a gaussian first. This ended up reducing a lot of noise, leading to needing a much lower threshold (from 0.3 to 0.1). In addition to that, the lines in the edge image are now much clearer and well-defined.

Original cameraman.png
Blurred with Gaussian
x direction (Dx) filter on blurred image
y direction (Dy) filter on blurred image
Edge image with 0.1 threshold

Instead of having to do two convolutions (one to apply Gaussian blur, then one to use the finite difference operator), we achieve the same effect by applying one convolution to the original image. By first precomputing the gaussian convolved with the finite difference operators, I could use a single DoG filter to get the same exact edge image result. Precomputing the DoG filter can save lots of computation for large images since the precomputation is much smaller than a convolution using a large image.

x direction DoG filter
y direction DoG filter
Edge image (same result as previous edge image)

Part 2: Fun with Frequencies!

Part 2.1: Image "Sharpening"

In order to "sharpen" an image, we can first extract the high frequencies of the image by subtracting a Gaussian blurred version from the original image. Then, adding those frequencies back to the image with a weight (alpha) will enhance finer details and edges within the image. This leads to a sharpening effect!

Original image
Blurred with Gaussian
High frequencies
Sharpened image

The way we sharpened the image took a few steps, but it can be simplified to one convolution. By simplifying the steps (and equation) that brought us to the final sharpened image, I found that the entire process was the same as convolving the original image by (identity + alpha * (identity - gaussian)), where identity is a zeroed out matrix with a 1 at the very center. This newly derived filter is the unsharp mask filter!

Original image
Unsharp mask filtered image
Original image
Unsharp mask filtered image

An additional way to test my unsharp mask filter is to blur an image, and then apply the unsharp mask filter on it. If the filter works well, then details that were blurred out should reappear in the filtered image. We can see that in the following image, the unsharp mask filter succeeds in adding back some details from the original image.

Original image
Blurred image
Unsharp mask filter on blurry image

Part 2.2: Hybrid Images

A hybrid image looks different depending how far away the observer is. This is possible since we see high frequencies better at close range and vice versa for low frequencies. Now, we can take the high frequencies of one image and overlay them on the low frequencies of another image. After aligning the images and calibrating the kernel size and sigma for the Gaussian filters used to extract the frequencies, we now have hybrid images!

Derek and Nutmeg

Original Derek
Hybrid image
Original Nutmeg

(Minecraft) Wolf

This hybrid image wasn't a good, likely due to how the real wolf has a ton of detail in the fur and silhouette. The two images didn't exactly align the best either since the bodies weren't in the same relative positions from the faces.

Original Minecraft wolf
Hybrid image
Original wolf

Pizookie!

Since this hybrid image worked pretty well both close and afar (aside from the edges of the pizza being very noticeable from close up), I included the Fourier transform for each image.

Original pizza
Hybrid image
Original cookie
Original pizza Fourier
Hybrid image Fourier
Original cookie Fourier
Low frequencies Fourier
High frequencies Fourier

Part 2.3-2.4: Gaussian and Laplacian Stacks + Multiresolution Blending (The Oraple!)

In order to start blending images together, I first have to implement Gaussian and Laplacian stacks. I've implemented a Gaussian stack by applying the same gaussian filter to each subsequent level of the stack. Then, for the Laplacian stack, each level is the difference between two consecutive layers of the Gaussian stack.

After constructing a Gaussian stack for each mask filter and a Laplacian stack for each image, we can now use them to blend the images. At each level, we multiply the Gaussian stack mask with the corresponding Laplacian stack image (direct pixel by pixel multiplication, not matrix multiplication) before combining the two with simple addition. At the very bottom level of the Laplacian stack, I added the bottom level of the corresponding Gaussian stack used to construct the Laplacian stack in order to restore the low frequencies of the original image when we eventually collapse the stack by adding all of the blended image layers to each other. I also made sure to clip any values outside of [0, 255].

I've illustrated the above process in the images below. In each layer of the stacks, from left to right, I have the left mask, the left mask * left image frequencies, the hybrid image at that frequency level, the right mask * right image frequencies, and the right mask. The penultimate images use the bottom of the Gaussian stack instead of the Laplacian stack (again, to add back the low frequencies). All of the center hybrid images for each frequency level get collapsed (added together) to produce the final image!

The Oraple

Final blended image!

Day or Night

Final blended image!

Disney in a Snow Globe (Irregular Mask)

Original snow globe image
Mask for snow globe (created using Photoshop)
Original Disney fireworks image
Final blended image