CS 194-26: Intro to Computer Vision and Computational Photography, Fall 2021

Project 2: Fun with Filters and Frequencies!

William Wang



Part 1: Fun with Filters!

Finite Difference Operator

The first filters we use are the finite difference operators. To do this, we convolve the original image with the difference operators, which gets our partial derivatives in the x and y direction of the image. Using these derivatives, we then get the gradient magnitude image by taking the L2 norm of the derivatives. Finally, we binarize the image by choosing a threshold and forcing the values to 0 or 1.

Below are the final and intermediate results of using the finite difference operators:

Cameraman
Partial Derivative in X
Partial Derivative in Y
Gradient Magnitude
Binary Gradient Magnitude (T = 0.065)

Derivative of Gaussian (DoG) Filter

To reduce the noise from the naive method of using finite difference operators, we can use a gaussian filter instead. The gaussian filter works as a low pass filter, resulting in a blurred, but smoother result.

Gaussian Kernel

By utilizing the derivative of the gaussian filter, we only need a single convolution instead of convolving twice: once for the finite difference and once for the gaussian. We obtain the following gaussian filters by convolving the gaussian filter with the finite difference operators.

Derivative of Gaussian Filter in X
Derivative of Gaussian Filter in Y

With the derivative of gaussian filters, we can simply convolve the original image with each of them, find the magnitude, and binarize as we did when using the finite difference operators

Blurred Partial dX of Cameraman
Blurred Partial dY of Cameraman
Grad Magnitude of Blurred Cameraman
Binary Grad Magnitude of Blurred Cameraman

Fun with Frequencies!

Image "Sharpening"

By separating the high and low frequencies, we can "sharpen" an image. We obtain the high frequencies of the original image by subtracting the low frequencies (from applying the gaussian filter) from the original. Then, we add back the high frequencies to the image, scaled by some constant, to sharpen it.

Below are examples of sharpened images. With the Taj Mahal, we see that the small features in the building are emphasized and made more more prominent. With the bear and the shark, we see clearer and darker edges around their figures, and for the bear, even its fur is more emphasized.

Taj Mahal
Sharp Taj Mahal
Brown Bear
Sharp Brown Bear
Shark
Sharp Shark

With the dog, we start with a sharp image. Then, we blur the dog with a low pass filter, and then resharpen it. As we can see below, the resharpened image is not as clear as the original sharp image. This is because blurring the picture makes us lose information that we can't simply retrieve again using existing frequencies.

Dog
Blurred Dog
Sharp Blurred Dog

Hybrid Images

Hybrid images occur when there are two different images, one at a low frequency and one at a high frequency. This combination of frequencies allows the viewer to see the high frequency image when up close, but the low frequency image from afar. To create this image from two images, we first align the images. Then, we pass one of the images through a low pass filter and sharpen the other. Then, by simply overlaying the pictures (adding the pixel values), we obtain our desired hybrid image.

Derek
Nutmeg
Hybrid Derek/Nutmeg

By analyzing the frequencies of the two images, we see that in the hybrid image's Fourier, the frequencies from nutmeg exist brighter, which means they have been "sharpened". Similarly, we see the opposite for Derek - the frequencies that align with his image are dimmed compared to his original image, since his image was passed through the low pass filter prior to combining the two images.

Derek Fourier
Nutmeg Fourier
Nutmeg-Derek Hybrid Fourier

Another example is seen with a cat who moves slightly. As the viewer moves away from the image, the cat is seen from having a high paw, laying on her side, laying straight up with a forward-facing head.

Cat 1
Cat 2
Hybrid Cats

Again, we try another movement in the hybrid images, but this time the hybrid image is not as effective. This is most likely due to the high contrast between the cow's black body/head and the relatively bright background. Since there is high contrast, the sharpened image of the cow is too "strong", and can still be seen relatively clearly even when the viewer moves away from the image.

Cow 1
Cow 2
Hybrid Cows

Gaussian and Laplacian Stacks

To obtain a Gaussian stack for an image, we pass the image through a low pass filter. As the stack deepens, we have the low pass filter that is used blurs the image exponentially (increasing sigma values). We then use this Gaussian stack to create the Laplacian stack, which can be done by subtracting pairs of the pictures in the Gaussian stack. Finally, to reconstruct the image, we need to add back the last layer of the Gaussian stack.

We create a mask and create a gaussian stack for it as well. Then, we apply multiply the pixel values in this stack to the laplacian stack for the image layer by layer. By repeating this process, but using the inverse of the mask, on the other image, and then overlaying the two results, we get the blended image as desired.

Right Apple Level 0
Left Orange Level 0
Oraple Level 0
Right Apple Level 2
Left Orange Level 2
Oraple Level 2
Right Apple Level 4
Left Orange Level 4
Oraple Level 4
Right Apple
Left Orange
Oraple

Bells and Whistles: By doing the blend above for each of the color channels individually on both images, and then restacking the channeles, we get our colored oraple! The colored image looks better blended as you can more clearly see where the apple and orange are represented, and the blended portion also looks more clear.

Oraple
Gray Oraple

I used a simple vertical mask to blend two images of the same cow - one with its head down, and the other with its head up. Thus, once blended, it looks like it has two heads!

Cow 1
Cow 2
Blended Cows
Mask

For the irregular mask, I used a circular mask to get the shape of the cat's head and put it on the watermelon. I create the mask using Preview, and using predefined shapes filled in with black and white.

Cat
Watermelon
Catermelon
Mask

Coolest Thing!

I thought that blending the images was very cool and had neat applications for making interesting images!