Project 2: Fun with Filters and Frequencies

Part 1.1: Finite Difference Operator

We can use the finite difference operators DxD_x and DyD_y  to filter in the x and y directions. The gradient magnitude is

M=(Ix)2+(Iy)2M = \sqrt{\left(\frac{\partial I}{\partial x}\right)^2 + \left(\frac{\partial I}{\partial y}\right)^2}

The gradient magnitude finds the rate at which pixels change in the image.

original image convolved with dx

original image convolved with dy

combined gradient (threshold = 0.1)
combined gradient (threshold = 0.15)
combined gradient (threshold = 0.20)
combined gradient (threshold = 0.25)

Part 1.2: Derivative of Gaussian (DoG) Filter

combined gradient convolved with Gaussian filter (threshold = 0.1)
combined gradient convolved with derivative of Gaussian filter (threshold = 0.1)

The Gaussian filter eliminates a significant amount of noise that was previously present in the combined gradient image with threshold=0.1. The edge detection is more accurate since the Gaussian filter keeps low frequency information and removes high frequency information.

The combined gradient convolved with the Gaussian filter and the derivative of the Gaussian filter are basically the same image.

Part 2.1: Image "Sharpening"

We can calculate a sharpened image with the following formulas. Let II be the original image, HH be the high frequency component, LL be the low frequency component, and SS be the sharpened image. α\alpha is a constant that increasingly sharpens the image.

H=IBH = I - B
S=I+αHS = I + \alpha H
taj.jpg before sharpening
taj.jpg after sharpening (alpha = 0.5)
taj.jpg after sharpening (alpha = 1)
taj.jpg after sharpening (alpha = 2)

penguin.jpg with no sharpening
penguin.jpg with sharpening (alpha = 2)
penguin.jpg blurred after sharpening, then sharpening again (alpha = 2)

Blurring the sharpened image and then sharpening again results in a very sharpened image with a significant amount of more details than the prior two images.

Part 2.2: Hybrid Images

To create hybrid images, we can use low frequencies and high frequencies of images to change how we see an image depending on how close or far we are from it.

derek.jpg

nutmeg.jpg

derek + nutmeg hybrid
derek + nutmeg hybrid with color

As I began testing out other images, I quickly recognized that the kind of images I picked were important. For example, merging Prof. Denero and Prof. Efros was a failure since these two images had different facial expressions and the two professors have significantly different facial features. I then knew I had to get images that already had vaguely similar features for a successful hybrid.

Bells and Whistles: I used color to enhance the effect. It seems that using color for both the low and high frequencies produced a significantly better quality hybrid image.

denero.jpg
efros.jpg
denero + efros hybrid

A lot of anime character designs are known to replicate cat facial features so I tried it out with One Piece’s Luffy and a cat. The hybrid is much better than the one before.

luffy.jpg
cat.jpg

luffy + cat hybrid

The Fourier transform helps us to visualize the frequencies within images and their hybrids.

derek.jpg FFT

derek.jpg low pass FFT

nutmeg.jpg FFT
nutmeg.jpg high pass FFT
derek + nutmeg hybrid

Part 2.3: Gaussian and Laplacian Stacks

The Gaussian stack is a series of the same image continuously blurred.

The Laplacian stack is calculated from the Gaussian stack such that the ith image in the Laplacian stack is the difference between the ith and i+1th image in the Gaussian Stack.

apple.jpg
orange.jpg

apple.jpg laplacian stack
orange.jpg laplacian stack

Part 2.4: Multiresolution Blending

Now that we have the Gaussian and Laplacian stacks of the apple and orange, we can start blending! Blending follows this process:

  1. Create a mask that determines how the two images should be blended. In this case, we use a vertical mask where the left half is black and the right half is white to produce a merging effect in the center vertically.
    mask for apple.jpg and orange.jpg
    1. Make a Gaussian stack for the mask. If we did not do this, the blended result would just have a distinct divide between the two images instead of a gradual divide.
    1. Create a masked Laplacian stack for each of the two images.
    1. Sum the two masked Laplacian stacks to get the blended image.
apple.jpg and orange.jpg blended

waffle.jpg
earth.jpg
waffle + earth blended

To achieve an irregular blend, I drew a simple mask that intends to get the eyes of one person and overlay it on another.

sanji.jpg
irregular_mask.jpg
zoro.jpg

zoro + sanji blended! I’m super happy that the eyes aligned so well.

zoro + sanji laplacian stack (level 0)
zoro + sanji laplacian stack (level 4)
zoro + sanji laplacian stack (level 2)
zoro + sanji laplacian stack (level 6)

zoro + sanji laplacian stack (level 8)
zoro + sanji laplacian stack (level 9)

Bells and Whistles: I used color to enhance the effect of all the blended images.

Reflection

The most important/interesting thing I learned from this project was how to create hybrid and blended images. I understand now that low and high frequencies can be manipulated to create new images and even toy with our perception. I also really enjoyed learning and implementing the mathematics behind these image-processing techniques. The idea that human vision can be represented and altered with math is pretty amazing, and I’m excited to learn more in this class!