Project 2 - Brian Agustino

Part 1 - Fun with Filters

In this part, we would be convolving and filtering using gaussian on the cameraman image

cameraman

Part 1.1 Finite Difference Operator

We first initialize the humble finite difference operators d_x and d_y as

finiteDifference

Where we would then convolve the cameraman image with d_x and d_y getting the partial derivative in x and y for the cameraman image

partial_x

Partial derivative of cameraman in x (partial_x.jpg)

partial_y

Partial derivative of cameraman in y (partial_y.jpg)

We would then get the gradient magnitude by doing the square root of the sum of the squared partial x and partial y. We would then get this gradient magnitude image

gradient_magnitude

Gradient Magnitude Image (gradient_magnitude.jpg)

We can then binarize the gradient magnitude image to get the edge image of the cameraman. For this edge image, I used a threshold of 0.25.

binary_gradient

Edge Image with Threshold of 0.25 (binary_gradient.jpg)

Part 1.2 - Derivative of Gaussian (DoG) Filter

In this part, we would be using gaussian as a low pass filter and get the blurry image of the cameraman image

We would first create the Gaussian filter with a sigma of 6 by using cv2.GetGaussianKernel() and take an outer product with its transpose to get the 2D gaussian filter.

After convolving this Gaussian filter with the cameraman image, we get the following blurred image:

blur_img

Blurred Image after convolving with Gaussian Filter (blur_img.jpg)

We would then do the same procedures as the previous part (Part 1.1) but convolving the finite difference operators d_x and d_y with the blurred image

partial_x_gaussian

The partial derivative of blurred cameraman in x (partial_x_gaussian.jpg)

partial_y_gaussian

The partial derivative of blurred cameraman in y (partial_y_gaussian.jpg)

We would then take the gradient magnitude of the blurred image by doing the square root of the sum of squared partial x and partial y. This would give us the gradient magnitude image that has been filtered with the Gaussian filter

gradient_gaussian_magnitude

Gradient Magnitude of Blurred Cameraman Image (gradient_gaussian_magnitude.jpg)

As we binarize the gradient magnitude of this image, we would get the following edge image:

edge_gaussian.jpg

Edge Image of Gaussian filtered Cameraman Threshold of 0.25(edge_gaussian.jpg)

We could see that there are no significant difference only that it is darker than the previous part.

Part 2 - Fun with Frequencies!

Part 2.1 - Image "Sharpening"

We would then try to "sharpen" an image by further increasing the intensity of the details of an image. The steps to sharpen an image is as follows:

  1. Create the 2D gaussian filter and convolve the image to get the blurred low pass filtered image
  2. Then we would substract the original image with the blurred image to get the high pass filtered image (detailed image)
  3. Since we now have the high pass filtered image or the detail of the image, we could multiply this image with a constant alpha (ex: 0.5) and add to the original image. This would intensify the detail of the image making it look "sharper"

Ex: Taj Mahal Image

taj

Taj Mahal Original Image (taj.jpg)

taj_sharpen

Sharpened Taj Mahal, alpha = 0.5, sigma = 3 (taj.jpg_sharpen.jpg)

Another sharpened image is the Eiffel Tower Image

eiffelTower

Eiffel Tower Original Image (eiffelTower.jpg)

eiffelTower_sharpen

Sharpened Eiffel Tower , alpha = 0.5, sigma = 3 (eiffelTower.jpg_sharpen.jpg)

Part 2.2 - Hybrid Images

Another cool trick we can implement on low and high frequency images are by combining 2 images and merging them into a hybrid image.

  1. We can achieve this by first aligning the two images such that it has similar features at similar position of the image (ex: The eye position of a cat and a person).
  2. Then we would create 2 different 2D gaussian filters and convolve the 2 images with this filter to get the blurred or low pass filtered image.
  3. We would then choose one of the image to be converted into a high pass filtered image by substracting it's original image with the low pass filtered image (ex: Image_1 is the low pass filtered image and Image_2 is the high pass filtered image)
  4. We would then sum both the images (Image_1 and Image_2) to get the hybrid image.

Ex: Derek and his former cat Nutmeg

nutmeg
Derek
nutmeg_derek

Hybrid Nutmeg and Derek (sigma 3, sigma 5) (nutmeg_derek.jpg)

Ex: Bill Gates and Elon Musk

Elon_Musk
Bill_Gates
Gates_Musk

Hybrid Elon Musk and Bill Gates (sigma 3, sigma 5) (gates_musk.jpg)

Ex: Lebron James and Stephen Curry

Ex: Lebron James and Stephen Curry

lebron

curry

curry_lebron

Hybrid Stephen Curry and Lebron James (sigma 3, sigma 5) (curry_lebron.jpg)

Part 2.3 - Gaussian and Laplacian Stacks

We implement the Gaussian Stack which is the gaussian filter for increasing sigma of the original image. In this project, each stack would be twice the sigma of the previous stack (ex: 2, 4, 8, 16, 32)

From this Gaussian Stack, we can get the Laplacian Stack which is just the difference between each stack. And that the last level of the Laplacian Stack is just the last level of the Gaussian Stack.

An implementation of the Gaussian and Laplacian Stack could be seen at the next part (Part 2.4)

Part 2.4 - Multiresolution Blending

In this part, we would be blending together an apple image and orange image into a oraple:

apple

Apple Image (apple.jpeg)

orange

Orange Image (orange.jpeg)

  1. In which we would be creating the Gaussian and Laplacian Stack from Part 2.3 for each of the images.

  2. We would also create a mask matrix (ex: half left is all 1 and half right is all 0). Which would be used to blend the laplacian images for a better transition

  3. For each Gaussian and Laplacian Stack we would also convolve the Gaussian filter on to the mask

  4. We would then get the level's blended image by applying the formula: blended_image = (filtered_mask laplacian_image_1) + ((1 - filtered_mask) laplacian_image_2)

  5. And we would then sum up all the blended image of each laplacian level to get a resulting image.

Ex: Oraple

laplace_1_im1

Apple Laplacian Level 1 (sigma 2)(apple.jpeg_2_laplace.jpg)

laplace_1_im2

Orange Laplacian Level 1 (sigma 2)(orange.jpeg_2_laplace.jpg)

combined_1

Combined Oraple Level 1 (sigma 2)(combined_2_laplace.jpg)

laplace_3_im1

Apple Laplacian Level 3 (sigma 8)(apple.jpeg_8_laplace.jpg)

laplace_3_im2

Orange Laplacian Level 3 (sigma 8)(orange.jpeg_8_laplace.jpg)

combined_3

Combined Oraple Level 3 (sigma 8)(combined_8_laplace.jpg)

laplace_5_im1

Apple Laplacian Level 5 (sigma 32)(apple.jpeg_32_laplace.jpg)

laplace_5_im2

Orange Laplacian Level 5 (sigma 32)(orange.jpeg_32_laplace.jpg)

combined_5

Combined Oraple Level 5 (sigma 32)(combined_32_laplace.jpg)

total_apple

Total Laplacian Apple (total_laplace_image1.jpg)

total_orange

Total Laplacian Orange (total_laplace_image2.jpg)

oraple

Blended Oraple (result.jpg)