CS 180 Project 2

Name: Brandon Wong

Overview

cameraman

Project 2 has multiple parts each with separate goals. Throughout the project, filters and frequencies are used to do accomplish a variety of different tasks.

Part 1: Fun with Filters

Part 1.1: Finite Difference Operator

In this part, I convolved the finite difference operators D_x = [1, -1] and D_y = [[1], [-1]] with the cameraman image shown above. This resulted in these two images:

cameraman_convolve_Dx

Convolved with D_x

cameraman_convolve_Dy

Convolved with D_y

I then combined the two images by computing the square root of the sum of the squares of the two images, resulting in the gradient magnitude image. Then, I binarized the image at the threshold of 0.3 to find the edge image with minimal noise.

cameraman_gradient_magnitude

Gradient Magnitude

cameraman_gradient_magnitude_binarized

Edge Image

Part 1.2: Derivative of Gaussian (DoG) Filter

In this part, I convolved the cameraman image with a gaussian created using the outer product of cv2.getGaussianKernel(15,2) to obtain a blurred version of the cameraman image. I then convolved this blurred image with D_x and D_y. These were then used to find the gradient magnitude image of the blurred image the same way as the previous part, and then this new gradient magnitude image was used to find the new edge image using the threshold 0.05, much smaller than in the previous part. Another difference was that the lines of the edge image became thicker in the edge image of the gaussian-blurred cameraman image compared to the unblurred version.

G_cameraman_convolve_Dx

Blurred Convolved with D_x

G_cameraman_convolve_Dx

Blurred Convolved with D_x

G_cameraman_gradient_magnitude

Blurred Gradient Magnitude

G_cameraman_gradient_magnitude_binarized

Blurred Edge Image

I also obtained very close results in a different way in this part. Instead of convolving the cameraman image with the gaussian, and then the D_x and D_y filters, I convolved the gaussian with the D_x and D_y filters to obtain the Derivative of Gaussian (DoG) filterns, and then convolved the cameraman with those resulting filters. This way, the cameraman only needed to be convolved with once for each filter result. The rest of the steps were the same, with a threshold at 0.05 again.

DoGx_cameraman_convolve

Convolved with DoG_x

DoGy_cameraman_convolve

Convolved with DoG_x

DoG_cameraman_gradient_magnitude

DoG Gradient Magnitude

DoG_cameraman_gradient_magnitude_binarized

DoG Edge Image

Part 2: Fun with Frequencies!

Part 2.1: Image "Sharpening"

In this part, I sharpened two images the given taj image and an image of a bowl of salmon and rice I had for dinner the other day. The images were sharped first by convolving them with a gaussians made from the outer product of cv2.getGaussianKernel(15,2) to obtain their low frequency versions. These low frequency versions were then subtracted from the original image to obtain just the high frequencies. The high frequencies were added to the original images to make them clearer and sharpen the original image. All of these steps were combined into a single step in the form of the unsharp mask filter, where the original images were convolved with 1 plus an alpha value multuplies by the identity filter minus the alpha value times the gaussian filter. I always set alpha to 1, it was always enough.

Taj:

taj

Original

taj_blur

Low Frequency

taj_high_freq

High Frequency

taj_sharp

Sharpened

Salmon Bowl:

salmon_bowl

Original

salmon_bowl_blur

Low Frequency

salmon_bowl_high_freq

High Frequency

salmon_bowl_sharp

Sharpened

The unsharp mask filter was also tested on an image that was blurred with the gaussian first. This image was of a crepe cake I made the other day. Unfortunately the original quality of the image could not be reobtained, and the new sharped image was decidedly worse than the original, with an odd shininess to it.

Crepe Cake:

crepe_cake

Original

crepe_cake_blurred

Blurred

crepe_cake_sharp

Sharpened

Part 2.2: Hybrid Images

In this part I blended the high frequencies of one image with the low frequencies of the other to create a hybrid image, where the low frequency image is what is seen from farther away while the low frequency image is what is seen while close up. I did this with three images the given Derek and Nutmeg images, an image of a bowl of chicken mapo tofu I made the other day and an image of a bowl of broccoli chicken I made another day, and an image of a salmon avocado and kimchi sandwich I made the other day and an image of a steak sandwich I made another day. The hybrid of the bowl of mapo tofu and broccoli chicken was a failure. While you can see a larger bowl (the mapo tofu) from farther away, the contents of the bowls really only look like broccoli chicken with a single distinct piece of tofu no matter the distance. This was likeley because both images have chicken pieces around the same size, which makes it hard to distinguish them. The tofu isn't particularly distinctive from pieces of chicken either, and the broccoli's darker color and what makes is distinct close up and farther away. The

Derek and Nutmeg:

derek

Derek

cat

Nutmeg

derekcat

Hybrid

Salmon Sandwich and Steak Sandwich:

salmon_sandwich

Salmon Sandwich

steak_sandwich

Steak Sandwich

salmon__sandwich_steak_sandwich

Hybrid

salmon_sandwich_fourier

Salmon Sandwich Fourier

steak_sandwich_fourier

Steak Sandwich Fourier

salmon_high_fourier

Salmon Sandwich High Fourier

steak_low_fourier

Steak Sandwich Low Fourier

steak_salmon_fourier

Steak and Salmon Sandwiches Fourier

Mapo Tofu and Broccoli Chicken Failure:

mapo_tofu

Mapo Tofu

broccoli_chicken

Broccoli Chicken

mapo_tofu_broccoli_chicken

Hybrid

Part 2.3: Gaussian and Laplacian Stacks

In this part, I obtained the gaussian and laplacian stacks of the given apple and orange images. The gaussian stacks were obtained by repeatedly convolving the previous level with the gaussian formed from the outer product of cv2.getGaussianKernel(20, 20) to get the next level. The laplacian stack were generated by subtracting the previous level with the next level to find the difference between the levels. These stacks are displayed below.

Apple Gaussian Stack

apple_gaussian_1

Level 5

apple_gaussian_2

Level 4

apple_gaussian_3

Level 3

apple_gaussian_4

Level 2

apple_gaussian_5

Level 1

Apple Laplacian Stack

apple_laplacian_1

Level 5

apple_laplacian_2

Level 4

apple_laplacian_3

Level 3

apple_laplacian_4

Level 2

apple_laplacian_5

Level 1

Orange Gaussian Stack

orange_gaussian_1

Level 5

orange_gaussian_2

Level 4

orange_gaussian_3

Level 3

orange_gaussian_4

Level 2

orange_gaussian_5

Level 1

Orange Laplacian Stack

orange_laplacian_1

Level 5

orange_laplacian_2

Level 4

orange_laplacian_3

Level 3

orange_laplacian_4

Level 2

orange_laplacian_5

Level 1

Part 2.4: Multiresolution Blending

In this part, I brought the stacks obtained through the methods in the previous part together to obtain the blended result of the two images based on input masks. The final blended images were obtained by summing up the laplacian stacks and their corresponding mask (obtained by convolving the mask of the previous level with a gaussian) up and then adding the final blurriest gaussian level multiplied the mask of its level on top of that. The two summed of separate stacks of the two different images were then summed together to obtain the final blended image, with the seam smoothed out. I did this on the given apple and orange images, an image from a breakfast taco I made the other day and a pot filled with mist from dry ice, and a different image of the same crepe cake from before and an image of cookie dough with a spoon in it. The last blended image is my favorite, it looks like the cookie dough is being spread over the crepe cake as frosting. The second two images have irregular masks, one with an oval and one with an oval with a rectangle sticking out of it. The results are shown below.

Apple and Orange:

apple

Apple

orange

Orange

oraple

Orapple

Breakfast Taco and Misty Pot:

breakfast_taco_misty_pot

Taco in Pot

Crepe Cake and Cookie Dough:

crepe_cake_cookie_dough

Cookie Dough Frosted Crepe Cake

Crepe Cake Laplacian Stack

close_crepe_cake_laplacian_0

Level 5

close_crepe_cake_laplacian_1

Level 4

close_crepe_cake_laplacian_2

Level 3

close_crepe_cake_laplacian_3

Level 2

close_crepe_cake_laplacian_4

Level 1

close_crepe_cake_laplacian_5

Level 0

Cookie Dough Laplacian Stack

cookie_dough_laplacian_0

Level 5

cookie_dough_laplacian_1

Level 4

cookie_dough_laplacian_2

Level 3

cookie_dough_laplacian_3

Level 2

cookie_dough_laplacian_4

Level 1

cookie_dough_laplacian_5

Level 0

Cookie Dough and Crepe Cake Laplacian Stack

crepe_cake_cookie_dough_laplacian_0

Level 5

crepe_cake_cookie_dough_laplacian_1

Level 4

crepe_cake_cookie_dough_laplacian_2

Level 3

crepe_cake_cookie_dough_laplacian_3

Level 2

crepe_cake_cookie_dough_laplacian_4

Level 1

crepe_cake_cookie_dough_laplacian_5

Level 0