Fun with Filters and Frequencies!

by Nir Levin

Overview

In this project, I manipulated images using convolutions and frequencies. An important concept that I used here a lot is the fact that gaussian convolution acts as a low pass filter. We can also subtract the convoluted image from the original image to get a result that acts as a high pass filter.

Part 1: Fun with Filters

Finite Difference Operator

In vector calculus, the gradient is the direction of greatest change, which is the vector comprised of partial derivatives in the X and Y directions. The magnitude of this vector is largest when there's a large change in pixel values, so it's a good way of finding edges.


Partial Derivative in X
Partial Derivative in Y
Gradient Magnitude
Edge Binarization (Threshold = 0.1)

Derivative of Gaussian (DoG) Filter

Convoluted with 5x5 gaussian w/ sigma = 2
Edge Binarization (Threshold = 0.1)

The main difference between this edge image and the previous one is that this one is smoother and less jagged. The previous image seems like it's made of a combination of vertical and horizontal lines.


Gaussian X Partial Derivative
Gaussian Y Partial Derivative
Edge Binarization Result (Threshold = 0.1) is similar to the previous method.

Part 2: Fun with Frequencies!

Part 2.1: Image "Sharpening"

It's possible to combine all the below operations into one gaussian which we can convolve with the original image to get the sharpened image. This gaussian is equal to ((1 + alpha) * unitImpulse - alpha * gauss), where alpha is the multiple of details we're adding and gauss is a simple unaltered gaussian.




Original
Image
Minus itself convolved
with a 5x5 gaussian
Equals just
the details.
Adding a multiple (alpha = 2) of the details
to the original image results in a "sharpened" image.

Below I attempt to blur an already sharp image, then resharpen it using the technique above. It's not perfect but the result is about halfway between the original and the blurred image.


Original image
is blurred.
And sort of brought back by adding the high pass details.

Hybrid Images

Here I wanted to create an image that looks like one thing when viewed up close and another when viewed from afar. In order to do this, I took advantage of our brain's innate ability to focus on the fine, and not broad, details up close but focus on the broad, and not fine, details from far away. This is accomplished by passing one image through a low-pass filter and the other one through a high-pass filter, and then averaging them.



Image 1: Joe Biden
Image 2: Anya Melfissa
Joe convolved with gaussian
Anya convolved with gaussian and subtracted from original image
Result

Fourier Analysis of Above Process



Image 1: Joe Biden log of Fourier Transform
Image 2: Anya Melfissa log of Fourier Transform
Joe low-pass log of Fourier Transform
Anya high-pass log of Fourier Transform
Result log of Fourier Transform

Other Hybrid Images

Image 1: Miki Lustig young
Image 2: Miki Lustig present-day
Result

Gaussian and Laplacian Stacks for Multiresolution Blending

I made the Gaussian stack of the Oraple by first convolving the apple and orange images with five separate times, each with a gaussian of different standard deviation. The sigma value is doubled for each level of the stack. I used sigma levels of 2, 4, 8, 16, and 32. Each level of the Laplacian stack below is the difference between two consecutive levels of the Gaussian stack.

In order to combine half of the apple and the other half of the orange, I used a step function mask. I created a Gaussian stack of this mask as well so that there's a more gradual rise from the dark left side to the bright right side of the mask. I then did element-wise multiplication of the mask and the orange for each level of the stack. I did the same for the apple and (1 - mask) in order to capture opposite sides of each fruit. For each level, I then added the masked apple and orange to get the rightmost column.

With the mask convolutions, I found it more effective to start with a mask that's too large, and then do a "valid" (as opposed to "same") style convolution with a large gaussian in order to get the most gentle gradient. When I used the "same" style convolution for the mask, there were very noticeable boundary artifacts.

These results below are calculated by adding up all the images in the laplacian stack.

Image 1: Apple
Image 2: Orange
Result: Oraple

More multiresolution bending

Image 1: Egg
Image 2: Galaxy
Result: Eggalaxy

The most interesting thing I learned in this assignment is how a Gaussian blur is just convolving the image with a matrix based off of a gaussian curve. I've used cv2.gaussianBlur a lot before but it's always been a black box for me.