CS 194-26 Project 2:

Fun with Filters and Frequencies

Leon Xu


1.1 Finite Difference Operator

We study the finite difference operator following image, beginning with the vertical and horizontal directions, then taking the magnitude:

Cameraman

With the following results:

Cameraman, Dx
Cameraman, Dy
Cameraman, gradient magnitude
Cameraman, gradient magnitude binarized

1.2 Derivative of Gaussian Filter

Now we try with the blurred cameraman image below. Note that the image is blurred, but it is difficult to tell on this writeup because the image is shrunk to be displayed here.

Cameraman blurred

Note that the binarized result is far less noisy than before, although the lines are thicker.

Cameraman blurred, Dx
Cameraman blurred, Dy
Cameraman blurred, gradient magnitude
Cameraman blurred, gradient magnitude binarized

We get the same results if we convolve the two convolution matrices together before applying to the cameraman.

Binarized edge image, combined convolutions
Binarized edge image, separate convolutions

1.3 Image Straightening

The original, unstraightened image we are working with:

Facade, tilted

Using the same process as in 1.2, we get a binarized gradient magnitude image. In addition, we compute a binarized gradient orientation image, binarized on the same threshold as the gradient magnitude.

Facade, binarized gradient magnitude
Facade, binarized gradient direction

From this, we obtain a historgram of the gradient orientations in \((-\pi, \pi)\):

Facade, gradient orientation histogram

and we try rotations in the range \([-10, 10]\) to see which maximizes the size of the bins near \(0\), \(90\), \(180\), and \(270\) degrees.

This results in the following best histogram and aligned image, with a -3 degree rotation:

Facade, aligned gradient orientation histogram
Facade, aligned and cropped

Alignment results on some other images. The result on the snow image was a bit off, likely because the plants and clouds confused the algorithm.

Tree, original
Tree, histogram
Tree, aligned histogram
Tree, aligned and cropped
Cambridge, original
Cambridge, histogram
Cambridge, aligned histogram
Cambridge, aligned and cropped
Momo, original
Momo, histogram
Momo, aligned histogram
Momo, aligned and cropped
Snow, original
Snow, histogram
Snow, aligned histogram
Snow, aligned and cropped

2.1 Image "Sharpening"

We can artificially sharpen an image by getting the image "details" as \(s(i) = i - G(i)\), where \(i\) is the original image and \(G\) applies a Gaussian smoothing filter. Then we add this sharpened image back in: \(i' = i + \alpha s(i)\) for some constant \(\alpha\).

Below, see the results on some images:

Taj Mahal, original
Taj Mahal, sharpened
Pencil, original
Pencil, sharpened
Momo, original
Momo, sharpened

However, this does not actually add any new detail, it just tries to emphasize what detail is already there. Consider this blurred image, re-sharpened through the above process: it is not as crisp as the original.

Momo, original
Momo, blurred
Momo, resharpened

2.2 Hybrid Images

We combine the low frequencies of one image with the high frequencies of another to create hybrid images. Note that the first image is high-passed, and the second is low-passed.

Nutmeg
Derek
Nutmeg and Derek
Nutmeg and Derek, with color
Momo
Me
Momo and Me
Momo and Me, with color
Tree
Car
Tree and Car
Tree and Car, with color
American Gothic
Skull
American Gothic and Skull
American Gothic and Skull, with color

Interestingly, the colored results seem to mostly use the colors of the low frequency components. It seems the color information of a picture may often be low frequency.

To get a closer look at what's going on, we can also look at the log magnitude of the Fourier transforms for the inputs, the filtered images, and the hybrid image. We will do this for the American Gothic and Skull images.

American Gothic, Fourier
American Gothic, high-passed Fourier
Skull, Fourier
Skull, low-passed Fourier
American Gothic and Skull, Fourier

I'm not really sure what causes the grid lines in the low passed skull's Fourier's log magnitude graph.


2.3 Gaussian and Laplacian Stacks

We get Gaussian stacks by repeatedly passing the image through a Gaussian filter, and Laplacian stacks by finding the difference between consecutive Gaussian stacks.

Mona Lisa

Gaussian stack:

Mona Lisa, Gaussian 0
Mona Lisa, Gaussian 1
Mona Lisa, Gaussian 2
Mona Lisa, Gaussian 3
Mona Lisa, Gaussian 4
Mona Lisa, Gaussian 5

Laplacian stack:

Mona Lisa, Laplacian 0
Mona Lisa, Laplacian 1
Mona Lisa, Laplacian 2
Mona Lisa, Laplacian 3
Mona Lisa, Laplacian 4

One thing we can notice on the Mona Lisa is that she is smiling at the first level of the Laplacian stack, but not the last.

We can also apply this procedure to one of the hybrid images from part 2.2:

American Gothic and Skull

Gaussian stack:

American Gothic and Skull, Gaussian 0
American Gothic and Skull, Gaussian 1
American Gothic and Skull, Gaussian 2
American Gothic and Skull, Gaussian 3
American Gothic and Skull, Gaussian 4
American Gothic and Skull, Gaussian 5

Laplacian stack:

American Gothic and Skull, Laplacian 0
American Gothic and Skull, Laplacian 1
American Gothic and Skull, Laplacian 2
American Gothic and Skull, Laplacian 3
American Gothic and Skull, Laplacian 4

In this way, we can roughly recover the original American Gothic and Skull images.


2.4 Multiresolution Blending

In this section, we blend images by blending their Laplacian layers (and the last Gaussian layer) with different levels of a Gaussian stack on a binary mask, such that higher frequency bands get a sharper mask and lower frequency bands get a blurrier one. Specifically, the equation at each level looks like $$L_c = G_m * L_a + (1 - G_m) * L_b$$ where \(L_a\), \(L_b\) are the Laplacian levels of the original images; \(G_m\) is the Gaussian level of the mask; and \(L_c\) is the Laplacian level of the result.

Below are some results using a binary left/right mask:

Apple
Orange
Oraple
Oraple, colored
Beginning of Sunset
End of Sunset
Sunset
Sunset, colored

The next results use an irregular mask.

Leo
Me
Eye mask
Leo with my eyes
Leo with my eyes, colored
Landscape
Death Star
Mask
That's no Moon!
That's no Moon!, colored

Finally, here are the masks as applied to various levels of the two images in the last blended image:

Landscape, level 0 Laplacian
Landscape, level 1 Laplacian
Landscape, level 2 Laplacian
Landscape, level 3 Gaussian
Death Star, level 0 Laplacian
Death Star, level 1 Laplacian
Death Star, level 2 Laplacian
Death Star, level 3 Gaussian