Project 2

1 Fun with Filters

Gradient magnitude gives us how steep the change in intensity across pixels are. So the higher the gradient magnitude, the more likely it lies on a real-life border, such as delineating the outline of an object. So if we identify regions with large such changes and filter out ones based on a threshold, they are more likely to be on edges of some shape. We'll try using this technique on the cameraman image.

Cameraman

Let's try to compute the gradient magnitude image. First, we have to get the partial derivative in x and y. This can be done by convolving with the finite difference operators, which are D_x = [1, -1] and D_y [[1], [-1]] for the x and y directions respectively.

Camx
Cameraman, x-gradient
camy
Cameraman, y-gradient

As we expected, the x-gradient reveals all vertical edges. This makes sense because if we detect change across the x-axis direction, it means the dividing line is a vertical line. Vice versa for the y-gradient.

Now to combine these two into a gradient magnitude. We can compute as the norm of each pixel in the x- and y-gradients. This is sqrt(x^2 + y^2) (arithmetic done entry-wise). We can binarize this by setting a threshold (i.e. alpha = 0.10), where all pixels above the value are rounded up to 1, or else are rounded down to 0.

Camx
Cameraman, gradient magnitude
Cameraman
Cameraman, gradient magnitude binarized

Now it's time to get rid of the noise with the DoG filter. First, we can try convolving the image with the Gaussian kernel and computing the gradient magnitude. We can convolve the finite difference filter with the Gaussian and see we get the same result.

gaus
Gaussian and convolve
gaus
DoG

These are a lot less noisy. You can also see that the outline of the cameraman is a lot more pronounced and recognizable, not to mention that it appears to be a set of continuous lines, instead of choppy discrete lines. It also captures all edges that have "weaker" edges, such as the cameraman's back leg. We can confirm that the results are identical and that convolution is associative. Namely: (img * gaussian) * (D_x) = (img) * (gaussian * D_x)

2 Fun with Frequencies

2.1 Image sharpening

Let's try sharpening an image. We'll put it through a low pass filter and subtract the result to strengthen high frequencies. For example:

gaus
Blurry Taj
gaus
Sharp Taj

It works on the Taj Mahal, but as a sanity check let's try a photo of Berkeley. (Ignore the small grey bubble at the bottom left. This is a screenshot of some image that I didn't want to pay for.)

gaus
Blurry Berkeley
gaus
Sharp Berkeley

This looks good. Let's try it on the golden gate bridge. We'll first blur the original image and try to sharpen it.

gaus
Original Golden Gate Bridge
gaus
Blurred Golden Gate Bridge
gaus
Blurred Golden Gate Bridge

Now note that the re-sharpened image isn't identical to the original image. From the blurring, we actually lost information. We cannot retrieve the original information by emphasizing high frequencies. One detail is that the "lines" that are almost overlapping but clearly distinguishable in the original image lose significant detail in the re-sharpened image. Particularly on the right side, they seem to be completely overlapping at times. If you zoom in far enough, you will also see that the details of the passing cars are far less noticeable. Finally, the movement of the water beneath seem unnatural, suggesting a rather rough texture rather than a smooth one.

2.2 Hybrid images

gaus
Derek
gaus
Nutmeg
gaus
Derek Nutmeg

Here's the log magnitude of the FFT.

gaus
Derek FFT
gaus
Nutmeg FFT
gaus
Derek Nutmeg FFT

Let's try this on a couple more images.

gaus
San Francisco 2003
gaus
San Francisco 1993
gaus
San Francisco new and old
gaus
Sriram from CS 162
gaus
Professor Ion
gaus
Sriion

However, combining President Biden and VP Harris doesn't work as well:

gaus
President Biden
gaus
VP Harris
gaus
Biden Harris

Their facial features overlap a lot, so the high frequency and the low frequency in the image blend together. But if you move far away enough, you can catch a glimpse of VP Harris.

2.3 Gaussian and Laplacian Stacks

Here's a recreation of the Laplacian stacks. The layers represent the 0th, 2nd, and 4th levels in this order.

gaus gaus gaus
gaus gaus gaus
gaus gaus gaus

2.4 Multiresolution blending

Now finally, the Orapple.

gaus

But I think we can make something far more interesting. We know there are bicolor cats. But can we create one with computers?

gaus gaus gaus

We can indeed. The alignment is a little off due to the nature of the tilt on the black cat's head, but this looks good.

We can actually generalize this masking process. We can have any 2D array of 1s and 0s, corresponding to portions of the images that we want to mask out.

gaus gaus

Now let's make a mask for the face.

gaus
Mask used

The final result:

gaus

This beautiful scene from the movie Titanic has been enhanced by former president George W. Bush. Technology is great.