CS 180 Project 2: Fun with Filters and Frequencies!


Ryan Campbell

Part 1.1: Finite Difference Operator

Starting with the cameraman image, we explore the capabilities of the finite difference operator. We define two filters D_x = [1, -1] and D_y = [1, -1]^T and convolve them with the cameraman image.

Image 1
original cameraman image
Image 2
cameraman convolved with D_x
(cameraman_x)
Image 2
cameraman convolved with D_y
(cameraman_y)

Next, we compute the gradient magnitude image by computing ((cameraman_x)+(cameraman_y))^0.5. In order to binarize this image, we set choose a threshold and set all values above it to be 1 and below it to be 0.

Image 1
gradient magnitude image of cameraman
Image 2
gradient magnitude image with threshold=0.1
Image 2
gradient magnitude image with threshold=0.3

Part 1.2: Derivative of Gaussian (DoG) Filter

As the previous results are noisy, we utilize a smoothing operator to reduce this noise. In particular, we use a Gaussian filter, G. This creates a blurred version of the cameraman image by convolving with a Gaussian (low-pass filter). Thus, we repeat the process described above, starting with a blurred version of the cameraman image.

Image 1
blurred cameraman image
Image 2
blurred cameraman image convolved with D_x
Image 2
blurred cameraman image convolved with D_y
Image 2
gradient magnitude image with threshold=0.1

Notice that here we are having to do four convolutions on the cameraman image (two for calculating the blurred convolution with D_x and two for calculating the blurred convolution with D_y). However, recall that convolution is a commutative operation. Thus, it should be able to reduce the number of convolutions we perform by half. That is, perform the first convolution between the D_x/D_y filter with G to get a Derivative of Gaussian filter (DoG). This is preferable because it is less expensive than performing multiple convolutions on the larger cameraman image.

Image 1
D_x convolved with G
(DoG_x)
Image 2
D_y convolved with G
(DoG_y)
Image 2
cameraman image convoled with DoG_x
Image 2
cameraman image convoled with DoG_x

Now we should see (and we do) that the gradient magnitude image is identical when comparing between the approach with separated convolutions and the approach that utilizes the DoG filters. Note that any small differences come from small padding errors (convolution does not normally preserve the size of an image), but these errors are negligble.

Image 2
gradient magnitude image with threshold=0.1
(4 convolutions on cameraman)
Image 2
gradient magnitude image with threshold=0.1
(2 convolutions on cameraman by utilizing DoG filters)

Part 2.1: Image "Sharpening"

Recall that the Gaussian filter G is a low-pass filter. In order to create a high-pass filter, we subtract the blurred version of the image (which contains the low frequencies) from the original image (which contains all frequencies), granting us an image with only high frequencies.

We can utilize the linearity of convolution to make this process into a single convolution filter, called the unsharp mask filter. We get this filter F by selecting some parameter alpha and then computing (1 + alpha) * I - alpha * G, where I denotes the unit impulse filter and '*' denotes scalar-filter multiplication, not convolution. Using this filter F yields the following results:

Image 1
original Taj Mahal image
Image 2
sharpened Taj Mahal
(alpha=1)
Image 2
sharpened Taj Mahal
(alpha=2)
Image 2
sharpened Taj Mahal
(alpha=4)
Image 2
sharpened Taj Mahal
(alpha=8)

Image 1
original guitar image
Image 2
sharpened guitar
(alpha=1)
Image 2
sharpened guitar
(alpha=2)
Image 2
sharpened guitar
(alpha=4)
Image 2
sharpened guitar
(alpha=8)
Image 2
sharpened guitar
(alpha=16)

Image 1
original piano image
Image 2
sharpened piano
(alpha=1)
Image 2
sharpened piano
(alpha=2)
Image 2
sharpened piano
(alpha=4)
Image 2
sharpened piano
(alpha=8)

Furthermore, we can attempt to 'regain' clarity from a blurred image by doing this process. That is, if we blur an image, we can attempt to 'unblur' it by sharpening it. Note that this doesn't recover the high frequencies that are lost during the blurring process, but it does emphasize the ones that remain.

Image 1
blurred Taj Mahal image
Image 2
sharpened blurred Taj Mahal
(alpha=1)
Image 2
sharpened blurred Taj Mahal
(alpha=2)
Image 2
sharpened blurred Taj Mahal
(alpha=4)
Image 2
sharpened blurred Taj Mahal
(alpha=8)

Image 1
blurred piano image
Image 2
sharpened blurred piano
(alpha=1)
Image 2
sharpened blurred piano
(alpha=2)
Image 2
sharpened blurred piano
(alpha=4)
Image 2
sharpened blurred piano
(alpha=8)

Part 2.2: Hybrid Images

Next, we seek to create hybrid images, images which appear to be one thing up close and another when further away. This is done by exploiting the fact that the human eye percieves higher frequencies when up close and lower frequencies when further away. Thus, in order to create a hybrid image, one can use a low-pass filter on one image, a high-pass filter on another image, and then average them. Some examples of carrying out this process are given below:

Image 1
man (unmodified picture)
Image 2
cat (unmodified picture)

Image 2
low-pass filter on cat
Image 1
high-pass filter on man
Image 2
catman

Image 2
low-pass filter on man
Image 1
high-pass filter on cat
Image 2
mancat



Image 1
my dog, Benny (unmodified picture)
Image 2
my cat, Franklin (unmodified picture)

Image 2
low-pass filter on Benny
Image 1
high-pass filter on Franklin
Image 2
Benlin



Image 1
my dog, Benny (unmodified picture)
Image 2
my cat, Franklin (unmodified picture)

Image 2
low-pass filter on Franklin
Image 1
high-pass filter on Benny
Image 2
Frenny

Notice that the color works better for the low-frequency component, though it does work for both. This makes intuitive sense, as the broad strokes of the hybrid image are determined by the low-frequency component, and thus its colors end up mattering more.

Image 1
a banana (unmodified picture)
Image 2
some Lego minions (unmodified picture)

Image 2
low-pass filter on banana
Image 1
high-pass filter on minions
Image 2
Bananaaaaaaaaaaa

Image 2
low-pass filter on banana
(color)
Image 1
high-pass filter on minions
(color)
Image 2
Bananaaaaaaaaaaa
(color)

For the above result (my favorite of the hybrid images), we can visualize the processes using frequency analysis with the log magnitude of the Fourier transform of the two input images, the filtered images, and the hybrid image.

Image 1
banana
(log magnitude of the Fourier transform)
Image 2
minions
(log magnitude of the Fourier transform)
Image 1
low-pass filter on banana
(log magnitude of the Fourier transform)
Image 2
high-pass filter on minions
(log magnitude of the Fourier transform)
Image 2
Bananaaaaaaaaaaa hybrid image
(log magnitude of the Fourier transform)

Unfortunately, this process of making hybrid images does not always work. Sometimes, the images cannot be properly aligned, one of the images dominates too much, or both mess with each other so much that everything becomes unintelligible. In the following example, the hybrid image fails because all of the words become illegible.

Image 2
a trick-or-treat sign (unmodified picture)
Image 1
a live, laugh, love sign (unmodified picture)

Image 2
low-pass filter on trick-or-treat
Image 1
high-pass filter on live, laugh, love
Image 2
Live, trick, laugh, love, or treat
(hybrid of the two signs)

Part 2.3: Gaussian and Laplacian Stacks

Next, we move forward by investigating multiresolution blending. In order to accomplish this task, it will be necessary to develop some machinery that can handle Gaussian and Laplacian stacks.

Gaussian stacks, G, are computed by taking an image and repeatedly applying a Gaussian filter onto it, placing an unblurred image in the start of the stack, G_0. Laplacian stacks, L, are computed by taking a Gaussian stack, [G_0, G_1, ..., G_n], and calculating L_i by G_i - G_(i+1) for i=0,1,...,n-1, and setting L_n to G_n. Thus, we note that L_0 + L_1 + ... + L_n is the original image.

The following are examples of Gaussian and Laplacian stacks, normalized for visualization purposes (with the first row being a Gaussian stack and the second row being a Laplacian stack):







Image 1













Image 2







Part 2.4: Multiresolution Blending (a.k.a. the oraple!)

Now that we can create Gaussian and Laplacian stacks, we are ready to create multiresolution blended images. We define blend_i = mGi * ALi + (1 - mGi) * BLi where mGi is the ith element of the Gaussian stack of the mask, ALi is the ith element of the Laplacian stack of image A, and BLi is the ith element of the Laplacian stack of image B. To get the final blended image, we sum up each of the blend_i. Note that all of the following images are once again normalized for visualization purposes.



Image 1
apple L_0 (aL0)
Image 2
orange L_0 (oL0)
Image 2
mask G_0 (mG0)
Image 2
blend_0 (mG0 * aL0 + (1 - mG0) * oL0)

Image 1
apple L_1 (aL1)
Image 2
orange L_1 (oL1)
Image 2
mask G_1 (mG1)
Image 2
blend_1 (mG1 * aL1 + (1 - mG1) * oL1)

Image 1
apple L_2 (aL2)
Image 2
orange L_2 (oL2)
Image 2
mask G_2 (mG2)
Image 2
blend_2 (mG2 * aL2 + (1 - mG2) * oL2)

Image 1
apple L_3 (aL3)
Image 2
orange L_3 (oL3)
Image 2
mask G_3 (mG3)
Image 2
blend_3 (mG3 * aL3 + (1 - mG3) * oL3)

Image 1
apple L_4 (aL4)
Image 2
orange L_4 (oL4)
Image 2
mask G_4 (mG4)
Image 2
blend_4 (mG4 * aL4 + (1 - mG4) * oL4)

Image 1
apple L_5 (aL5)
Image 2
orange L_5 (oL5)
Image 2
mask G_5 (mG5)
Image 2
blend_5 (mG5 * aL5 + (1 - mG5) * oL5)

Image 1
apple L_6 (aL6)
Image 2
orange L_6 (oL6)
Image 2
mask G_6 (mG6)
Image 2
blend_6 (mG6 * aL6 + (1 - mG6) * oL6)

Image 1
orapple





Image 1
AL_0
Image 2
BL_0
Image 2
mG0
Image 2
blend_0

Image 1
AL_1
Image 2
BL_1
Image 2
mG1
Image 2
blend_1

Image 1
AL_2
Image 2
BL_2
Image 2
mG2
Image 2
blend_2

Image 1
AL_3
Image 2
BL_3
Image 2
mG3
Image 2
blend_3

Image 1
AL_4
Image 2
BL_4
Image 2
mG4
Image 2
blend_4

Image 1
AL_5
Image 2
BL_5
Image 2
mG5
Image 2
blend_5

Image 1
AL_6
Image 2
BL_6
Image 2
mG6
Image 2
blend_6

Image 1
beach
Image 1
the stars
Image 1
Beach among the stars





Image 1
AL_0
Image 2
BL_0
Image 2
mG0
Image 2
blend_6

Image 1
AL_1
Image 2
BL_1
Image 2
mG1
Image 2
blend_1

Image 1
AL_2
Image 2
BL_2
Image 2
mG2
Image 2
blend_2

Image 1
AL_3
Image 2
BL_3
Image 2
mG3
Image 2
blend_3

Image 1
AL_4
Image 2
BL_4
Image 2
mG4
Image 2
blend_4

Image 1
AL_5
Image 2
BL_5
Image 2
mG5
Image 2
blend_5

Image 1
AL_6
Image 2
BL_6
Image 2
mG6
Image 2
blend_6

Image 1
AL_7
Image 2
BL_7
Image 2
mG7
Image 2
blend_7

Image 1
AL_8
Image 2
BL_8
Image 2
mG8
Image 2
blend_8

Image 1
Ryan (me!)
Image 1
lava world
Image 1
Is it just me or is it hot in here?


Note that the irregular mask for the above process was created on my iPad by drawing over the initial photo of me. I'm very pleased with how all of the blended images turned out. The multiresolution blending process produces significantly better results than just simply stitching images together.