Project 2 CS 194-26: Fun with Filters and Frequencies!

By Diego Uribe

Project Description

In this project I woked on 2D convolutions of images with specific filters. These included finite difference operator filters and derivative of gaussian filters. In the second half I worked on filtering, extracting and removing certain frequencies from images. This allowed me to write image sharpening algorithms, create hybrid images, create gaussian and laplacian stacks of images, and make multiresolution blendings of images.

Part 1: Fun with Filters

Part 1.1: Finite Difference Operator

For this part I took the partial derivative with respect to x and y of the cameraman image. Then computed the gradient magnitue image and binarized it to create an edge image. The gradiend magnitude is computed by taking the norm of the gradient with respect to x and the gradient with respect to y of every pixel on the image.

The threshold I found was only considering pixels with a gradient magnitude greater than 0.06

Original Cameraman Image

Gradient Magniute Finite Difference Operator Image

Binarized Gradient Magniute Finite Difference Operator Image

Part 1.2: Derivative of Gaussian (DoG) Filter

For this part I created a blurred version of the original image by convolving it with a guassian filter. Then repeated the procedure in Part 1.1. The images below show that by applying the gaussian filter to the original image we removed the high frequencies in it. This allowed us to remove some of the noise in the original edge image. As we can see, the edges in the edge images are much more clear and we have reduced the noise substantially.

Blurred Cameraman DoG Two Convolutions

Difference between original image and the blurred Cameraman

Gradient Magnitude DoG Two Convolutions

Binarized Gradient Magnitude DoG Two Convolutions

The results below are the same but they were generated using a single convolution by creating a derivative of gaussian filters.

Derivative of Gaussian Dx

Derivative of Gaussian Dy

Gradient Magnitude DoG One Convolution

Binarized Gradient Magnitude DoG One Convolution

Part 1.3: Image Straightening

I could not get my algorithm to work. It always returned that the 0th degree rotation was the best. Please look at my code for some partial credit. I made a lot of progress just could not get the final result to work.

Part 2: Fun With Frequencies

Part 2.1: Image "Sharpening"

In this part I implemented an image sharpening algorithm. It takes a blury image and sharpens it by subtracting the blurred version from the original image to get the high frequencies of the image. Then I added this high frequencies back to the original image which "sharpened" it. I did this using one convolution and two convolutions. The results below were generated using one convolution.

Original Taj Image

Sharpened Taj Image

Other Images

Original Egypt Pyramid Image

Sharpened Egypt Pyramid Image

Original NYC Image

Sharpened NYC Image

Original Costa Rica Image

Sharpened Costa Rica Image

Sharpenning a Blurred Image

For this part, I selected a sharp image of a landscape. Then I blurred it and resharpened it. From the results, we can see that I was able to recover most of the details in the original image through the resharpening process. Nevertheless, some of the high frequencies were lost when we blurred the image and I was unable to recover them fully. Maybe I could try resharpening it twice.

Original Landscape Image

Blurred Landscape Image

Sharpened (blurred) Landscape Image

Part 2.2: Hybird Images

In this part I made hybrid images. The first image was passed through a low pass filter to only have low frequencies while the second image was passed through a high-pass filter to only contain high frequences. Then I added the two images. Below I also show the fourier analysis.

Original Derek Image

Original Nutmeg Image

Blurred Derek Image

Sharpened Nutmeg Image

Hybrid Nutmeg, Derek Image

Other Hybrid Images (Obama Trump)

Original Trump Image

Original Trump Image Fourier Analysis

Original Obama Image

Original Obama Image Fourier Analysis

Blurred Trump Image

Blurred Trump Image Fourier Analysis

Sharpened Obama Image

Sharpened Obama Fourier Analysis

Hybrid Trump Obama Image

Hybrid Trump Obama Image Fourier Analysis

Other Hybrid Images (Bear Lion)

Original Bear Image

Original Bear Image Fourier Analysis

Original Lion Image

Original Lion Image Fourier Analysis

Blurred Bear Image

Blurred Bear Image Fourier Analysis

Sharpened Lion Image

Sharpened Lione Fourier Analysis

Hybrid Bear Lion Image

Hybrid Bear Lion Image Fourier Analysis

Part 2.3: Gaussian and Laplacian Stacks

In this part I implemented a Gaussian and Laplacian Stack. Here are the results of the laplacian and gaussian stacks on the Salvador Dali painting of Lincoln and Gala. Please note the the first image in the stack is the original image. I included it for comparing!

Original Salvador Dali Painting Image

Gaussian Stack of Salvador Dali Painting

Laplacian Stack of Salvador Dali Painting

Gaussian and Laplacian Stacks of Trump/Obamas Hybrid Image

Original Trump Obama Hybrid Image

Gaussian Stack of Trump Obama Hybrid Image

Laplacian Stack of Trump Obama Hybrid Image

Part 2.4: Multiresolution Blending (a.k.a. the oraple!)

This part of the project consisted on implementing Multiresolution Blending. For this, I selected two images. Then I computed the laplacian stack for each of the two images. Then I came up with a mask to unite the images. I took the gaussian stack of this mask. Finally, I blended the laplacian stacks of the images with the guassian stack of the mask to create the multiresolution blended image.

Oraple

Original Apple Image

Original Orange Image

Image

Laplacian Stack of Apple Image

Laplacian Stack of Orange Image

Guassian Stack of Mask Image

Oraple Image

Mars and Earth Multiresolution Blending

Original Earth Image

Original Mars Image

Image

Laplacian Stack of Earth Image

Laplacian Stack of Mars Image

Earthmars Image

Using an Irregular Mask: FireWater

Original Waterfire Image

Original Fire Image

Image

Laplacian Stack of Water Image

Laplacian Stack of Fire Image

Guassian Stack of Mask Image

Waterfire Image