Project 2: Fun with Filters and Frequencies!

Filters/ Frequencies/ Sharpening/ Hybrid / Stacks/ Blending

Yuqin Jiao


Overview

This project is about image blurring, sharpen, hubrid, blending with the use of filters, frequencies, stack functions.

Part 1: Fun with Filters

Part 1.1: Finite Difference Operator: description of gradient magnitude computation

For computing gradient magnitude, I first applied Dx([[1, -1]]) and Dy([[1], [-1]]) to convolve with one image channel, then I got partical derivative x and partical derivative y. Then I used "np.sqrt(partial_derivative_x**2 + partial_derivative_y**2)" to compute gradient_magnitude. I chose threshold = 0.2 when binarizing the gradient magnitude image, after that, I got the first edge image[fig 1_1_1].

Part 1.2: Derivative of Gaussian (DoG) Filter: convolution is commutative

After creating a blurred version of the original image by convolving with a gaussian, I convolved (Image * G) with Dx and Dy separately, after getting new partial derivative x and y, I chose threshold = 0.04 to get the edge image[figure1_2_1], the difference between the new edge image and [figure1_1_1] is: the new edge image has less noise, and the edge is more clear and bloder.

To do the same thing with a single convolution, I first convolved G with Dx and Dy, then convolve the result with original image, after choosing the same threshold = 0.04, I got an edge image[figure1_2_2], which is the same result as [figure1_2_1]. So the same results from two processes have been verified. This process shows that convolution is commutative.

Description of figure1_1_1
[figure1_1_1] Edge Image from Part 1.1
Description of figure1_2_1
[figure1_2_1] Edge Image from Part 1.2 using (Im * G) * [Dx and Dy]
Description of figure1_2_2
[figure1_2_2] Edge Image from Part 1.2 using (G * [Dx and Dy]) * Im

Part 2: Fun with Frequencies

Part 2.1: Image Sharpening

According to the formula: f +α( f − f ∗ g) = (1+α) f −α f ∗ g = f ∗((1+α)e −αg). After getting the blurred image using "f * g", I subtracted it from the original image f. And I applied alpha = 1 to each 3 channels, after that, I got "f +α( f − f ∗ g)", then I combined this into the single convolutio operation, called unsharp mask filter, which is "(1+α)e −αg". Then I applied this unsharp mask filter to the original image.

I first used image taj to get the sharpend result [figure2_1_3] and [figure2_1_4], then I downloaded another image[figure2_1_5] (https://www.pinterest.com/pin/155303888060898481/), then I blurred it using gaussian kernel to get blurred image[figure2_1_6], I applied the filter to original image to sharpen it, then I got the sharpen image[figure2_1_7] and image[figure2_1_8]. I found that when I selected alpha = 1 or 2, I got the sharpened image more sharpening than the original image.

I then tried the same process to the other image (https://www.pinterest.com/pin/155303888068797329/). I found that when I selected alpha = 1 or 2, I got the sharpened image more sharpening than the original image.

Description of figure2_1_1
[figure2_1_1] original image
Description of figure2_1_2
[figure2_1_2] blurred image
Description of figure2_1_3
[figure2_1_3] sharpened image with alpha = 1
Description of figure2_1_4
[figure2_1_4] sharpened image with alpha = 2
Description of figure2_1_5
[figure2_1_5] original image
Description of figure2_1_6
[figure2_1_6] blurred image
Description of figure2_1_7
[figure2_1_7] sharpened image with alpha = 1
Description of figure2_1_8
[figure2_1_8] sharpened image with alpha = 2
Description of figure2_1_9
[figure2_1_9] original image
Description of figure2_1_10
[figure2_1_10] blurred image
Description of figure2_1_11
[figure2_1_11] sharpened image with alpha = 1
Description of figure2_1_12
[figure2_1_12] sharpened image with alpha = 2

Part 2.2: Hybrid Images

For hybriding images of the given example, after alignin images, I used the cat image as the high frequency image, which means show the edge of the cat, I used the human image as the low frequency image, which means blur this image, using it as a background. The result of the given example is showing as follows[figure2_2_1].

Description of figure2_2_1
[figure2_2_1] result of the given hybrid image

For the Fourier analysis, I made fourier image of aligned cat image[figure2_2_2], align human image[figure2_2_3], low frequency[figure2_2_4], high frequency[figure2_2_5], hybrid image[figure2_2_6]. The results are as follows.

Description of figure2_2_2
[figure2_2_2] fourier image of input cat image
Description of figure2_2_3
[figure2_2_3] fourier image of input human image
Description of figure2_2_5
[figure2_2_5] fourier image of filtered cat image
Description of figure2_2_4
[figure2_2_4] fourier image of filtered human image
Description of figure2_2_6
[figure2_2_6] fourier image of hybrid image

Hybrid images using other example1(success): I first tried to hybrid two animal, with sigma1 = 0, sigma2 = 10, ksize1 = 50, ksize2 = 10, that looks ok for hybrid. These two images are downloaded from pinterest.

Description of figure2_2_7
[figure2_2_7] high frequency image
Description of figure2_2_8
[figure2_2_8] high frequency image
Description of figure2_2_9
[figure2_2_9] hybrid image

Hybrid images using other example2(success): I first tried to hybrid two animal, with sigma1 = 0, sigma2 = 10, ksize1 = 50, ksize2 = 10, that looks ok for hybrid. These two images are downloaded from pinterest.

Description of figure2_2_10
[figure2_2_10] high frequency image
Description of figure2_2_11
[figure2_2_11] high frequency image
Description of figure2_2_12
[figure2_2_12] hybrid image

Hybrid images using other example3(failure): When I tried to hybrid a emoji and a soccer, with sigma1 = 0, sigma2 = 10, ksize1 = 50, ksize2 = 10, the result is not good, I think the reason is that the soccer has explicit edge and color difference, so can not be used as the low frequency image(background). These two images are downloaded from pinterest.

Description of figure2_2_13
[figure2_2_13] high frequency image
Description of figure2_2_14
[figure2_2_14] high frequency image
Description of figure2_2_15
[figure2_2_15] hybrid image

Bells & Whistles for Part 2.2

Since I used color images as input (I put 3 channels to the hybrid function, and combined the 3 output channels to the output image), to compare the result between gray image input and the color image input, I used rgb2gray to converted the color image to gray, and then I got the following high frequency image[figure2_2_16], low frequency image[figure2_2_17], and hybrid result image[figure2_2_18]. It looks like the high frequency image looks the same as color high frequency image, but the low frequency image looks not as clear as the color low frequency image. So in this case, the hybrid result has a more blur background, so may be not obvious enough when looking far from it.

Description of figure2_2_16
[figure2_2_16] high frequency image
Description of figure2_2_17
[figure2_2_17] high frequency image
Description of figure2_2_18
[figure2_2_18] hybrid image

Multi-resolution Blending and the Oraple Journey

Part 2.3: Gaussian and Laplacian Stacks

For creating gaussian and laplacian stacks, I first created a gaussian stack, using channels as input, and each level [i] is blurred based on the previous [i-1] level. Then for laplacian stack, the input are also channels, the laplacian level [i] = gaussian level [i] - gaussian level [i+1], the last laplacian level is equal to the gaussian level [i]. To get color image, I used np.dstack to combine 3 channels at each level.

Then I built a binary mask, and also put the mask into guassian stack function with 7 times. I also applied laplacian stack to the apple and orange images, I got the masked apple and orange image at level0, level2, level4 using "GR * apple_image_levels[i]" for apple, "(1 - GR) * orange_image_levels[i]" for orange. To get the final masked apple and orange image, I added each level together, then the results are displayed in [figure2_3_4] and [figure2_3_8].

To get the oraple image, at each level, I used "GR* apple_image_levels[i] + (1 - GR) * orange_image_levels[i]" to get the blended image at each level, and for the final blended image, I sum them up to get the oraple[figure2_3_12] image result.

Description of figure2_3_1
[figure2_3_1] masked apple at level 0
Description of figure2_3_5
[figure2_3_5] masked orange at level 0
Description of figure2_3_9
[figure2_3_9] blended image at level 0

Description of figure2_3_2
[figure2_3_2] masked apple at level 2
Description of figure2_3_6
[figure2_3_6] masked orange at level 2
Description of figure2_3_10
[figure2_3_10] blended image at level 2

Description of figure2_3_3
[figure2_3_3] masked apple at level 4
Description of figure2_3_7
[figure2_3_7] masked orange at level 4
Description of figure2_3_11
[figure2_3_11] blended image at level 4

Description of figure2_3_4
[figure2_3_4] masked apple summed
Description of figure2_3_8
[figure2_3_8] masked orange summed
Description of figure2_3_12
[figure2_3_12] summed blended image(oraple)

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

The oraple has been make in part 2.3, as shown in [figure2_3_12]. In this part, I used 3 pair of images with irregular masks to bled them using different parameters.

The first pair of images are the building and slum, downloaded from https://www.pinterest.com/pin/1139762618189519375/ and https://www.pinterest.com/pin/968133251120044619/.

Description of figure2_4_1
[figure2_4_1] slums
Description of figure2_4_2
[figure2_4_2] buildings
Description of figure2_4_3
[figure2_4_3] mask for first pair of image

Description of figure2_4_4
[figure2_4_4] blended image of first pair images

The second pair of images are the cat and bread, downloaded from https://www.pinterest.com/pin/627126316885027022/ and https://www.pinterest.com/pin/32510428552727642/.

Description of figure2_4_5
[figure2_4_5] cat
Description of figure2_4_6
[figure2_4_6] bread
Description of figure2_4_7
[figure2_4_7] mask for second pair of image

Description of figure2_4_8
[figure2_4_8] blended image of second pair images

The third pair of images are the cat and giraffe, downloaded from https://www.pinterest.com/pin/627126316885027022/ and https://www.pinterest.com/pin/32510428552727642/.

Description of figure2_4_9
[figure2_4_9] cat
Description of figure2_4_10
[figure2_4_10] giraffe
Description of figure2_4_11
[figure2_4_11] mask for third pair of image

Description of figure2_4_12
[figure2_4_12] blended image of third pair images

Bells & Whistles for Part 2.3

Since I used color images as input (I put 3 channels to the gaussian and laplacian stack functions, and combined the 3 output channels to the output image), to compare the result between gray image input and the color image input, I used rgb2gray to converted the color image to gray, and then I got the following images from [figure2_5_1] to [figure2_5_12].

Description of figure2_5_1
[figure2_5_1] masked apple at level 0
Description of figure2_5_5
[figure2_5_5] masked orange at level 0
Description of figure2_5_9
[figure2_5_9] blended image at level 0

Description of figure2_5_2
[figure2_5_2] masked apple at level 2
Description of figure2_5_6
[figure2_5_6] masked orange at level 2
Description of figure2_5_10
[figure2_5_10] blended image at level 2

Description of figure2_5_3
[figure2_5_3] masked apple at level 4
Description of figure2_5_7
[figure2_5_7] masked orange at level 4
Description of figure2_5_11
[figure2_5_11] blended image at level 4

Description of figure2_5_4
[figure2_5_4] masked apple summed
Description of figure2_5_8
[figure2_5_8] masked orange summed
Description of figure2_5_12
[figure2_5_12] summed blended image(oraple)

It seems like the result is not as good as the color input result, especially the orange is not clear in gray image. So in my previous part 2.3, since I'v used color image as input, so I've enhanced the effect using color.

Conclusion

I think I've learned about how to blur and sharpen the image, especially the algrithm of sharpen is really efficient. And I also learned about the approach to blend two images, and how to deal with the boundary is really helpful and fun!