This project is about image blurring, sharpen, hubrid, blending with the use of filters, frequencies, stack functions.
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].
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.
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.
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].
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.
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.
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.
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.
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.
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.
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/.
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/.
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/.
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].
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.
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!