CS 180 Proj 2: Fun with Filters and Frequencies!

1.1: Finite Difference Operator

First, I convolved the image of the cameraman with the finite difference operators D_x = [1, -1] and D_y = [[1], [-1]] to get the image's x-partial derivative and y-partial derivative. I then used the gradient magnitude formula to create the gradient magnitude image of the cameraman. The gradient magnitude formula is sqrt(xpartial**2 + ypartial**2). In order to generate the edge image of the cameraman, I used a threshold = 0.2.

Original Cameraman Image

Monastery Image

X-partial Derivative

Monastery no crop Image

Y-partial Derivative

Monastery no crop Image

Gradient Magnitude Image

Monastery no crop Image

Cameraman Edge Image

Monastery no crop Image

1.2: Derivative of Gaussian Filters

In this part, I convolved the image of the cameraman with a gaussian filter in order to blur the image. The 1d gaussian kernel was created using cv2.getGaussianKernel() with a kernel size = 2 and a standard deviation = 10. The 2d gaussian kernel was created by taking an outer product of the 1d gaussian with its transpose. I then repeated the same steps for the previous part using the blurred image. The most notable difference between part 1.2 and 1.1 was that the edges were much more defined in the edge image of 1.2. The blurring effect also made the edges smoother in 1.2.

Blurred Cameraman Image

Monastery Image

X-partial Derivative with Gaussian

Monastery no crop Image

Y-partial Derivative with Gaussian

Monastery no crop Image

Blurred Gradient Magnitude Image

Monastery no crop Image

Blurred Cameraman Edge Image

Monastery no crop Image

Another approach I took with this part was to convolve the gaussian filter with D_x and D_y. Then, I used these Derivative of Gaussian filters in the same process as 1.1. I convolved these DoG filters with the original cameraman image. After producing these images, I can confirm that both methods produce the same results.

D_x Gaussian Filter

Monastery Image

D_y Gaussian Filter

Monastery Image

D_x with DoG

Monastery no crop Image

D_y with DoG

Monastery no crop Image

DoG Gradient Magnitude Image

Monastery no crop Image

DoG Cameraman Edge Image

Monastery no crop Image

2.1: Image Sharpening

First, I created a 2d gaussian kernel using cv2.getGaussianKernel() with a kernel size = 10 and a standard deviation = 2. I then convolved this gaussian kernel with the original image of the Taj Mahal to blur it. I then subtracted the blurred image from the original image to produce an image of the high frequencies. I then multiplied the high frequency image with an alpha value which I declared as alpha = 2, and added this back to the original image. Formula: Sharpened_image = original_image + alpha * high_frequency_image.

Original Taj Mahal Image

Monastery no crop Image

Blurred Taj Mahal Image

Monastery no crop Image

High Frequency Taj Mahal Image

Monastery no crop Image

Sharpened Taj Mahal Image

Monastery no crop Image

Here are the results of the sharpening effect on a picture of myself. This time I used a kernel size = 30 and a standard deviation = 100. Alpha was still set to a value of 2.

Original Wesley Image

Monastery no crop Image

Blurred Wesley Image

Monastery no crop Image

High Frequency Wesley Image

Monastery no crop Image

Sharpened Wesley Image

Monastery no crop Image

2.2: Hybrid Images

The goal of this part is to take two different images and create a hybrid image. In this hybrid image, the viewer will be able to see one picture from up close and the other picture from far away. To do this, I applied a high pass filter to one image and a low pass filter to the other image. For the low_pass, I convolved a gaussian kernel to the image to create a blurred version of that image. For the high_pass, I first created the blurred version of the image and then subtracted the blurred version from the original version. I then blended the high frequency image with the low frequency image to create the hybrid image.

Derek Image

Monastery no crop Image

Nutmeg Image

Monastery no crop Image

Hybrid Image

Monastery no crop Image

Here's another example with two different images along with the Fourier analysis, which shows the log magnitude of the Fourier transform for each image.

Here's an example of a failed hybrid image between Mike Wazowski and Mario. This hybrid image failed due to Mike Wazowski only having one eye to Mario's two eyes. This made it difficult to effectively align the images.

Mike Image

Monastery no crop Image

Mario Image

Monastery no crop Image

Hybrid Image

Monastery no crop Image

2.3: Gaussian and Laplacian Stacks

In this part, I created Gaussian and Laplacian stacks for the images that I want to blend together. For the apple and orange images, I first created Gaussian stacks with 5 levels each. I used a Gaussain kernel with a kernel size = 10 and a standard deviation = 10 to create increasingly blurred images at each level. I would take the image at the current top level and then apply the blur to that image. I then placed the newly blurred image at the top of the stack. To create the Laplacian stack, I took the Gaussian stack and subtracted the layer of the next index from the layer of the current index to create a series of high frequency images. The last layer of the Laplacian stack is the same as the last layer of the Gaussian stack.

Apple Gaussian Stack

Monastery no crop Image

Orange Gaussian Stack

Monastery no crop Image

Apple Laplacian Stack

Monastery no crop Image

Orange Laplacian Stack

Monastery no crop Image

2.4: Multiresolution Blending

To finish up the set up for the blending of images, I created another Gaussian stack for the mask that I would be using to combine the images of the apple and orange. For this mask, I used a kernel size = 100 and a standard deviation = 5000. I then iterated through the layers of the Gaussian stack of the mask along with the layers of the apple and orange Laplacian stacks. For each layer, I multiplied the image of the apple Laplacian with (1 - Gaussian mask) and added that to the product of the orange Laplacian with (Gaussian mask). After iterating through all of the layers, I then summed up all of the layers of the resulting stack to produce the final oraple image.

Oraple Stack

Monastery no crop Image

Apple Image

Monastery no crop Image

Orange Image

Monastery no crop Image

Oraple Image

Monastery no crop Image

Here are some other example images!

Kobe Image

Monastery no crop Image

Jordan Image

Monastery no crop Image

Kobe Jordan Image

Monastery no crop Image

Wesley Image

Monastery no crop Image

Vince Image

Monastery no crop Image

Wesley Vince Image

Monastery no crop Image

Reflection

Overall, I really enjoyed this project. It was really interesting to learn about all of the flitering and blending techniques. The most important thing I learned from this project is becoming familiar with all of the necessary steps that go into blending an image. I was able to gain a good understanding of Gaussian and Laplacian stacks, and I was also able to gain expertise in tweaking parameters to improve upon an image's outcome.