CS 180 Fall 2024

Project 2 by Lawrence Shieh

Part 1.1: Finite Difference Operator

Include a brief description of gradient magnitude computation:
To get the gradient of the image, we first have to realize we are taking convolution in two directions. The first direction Dx = [1, -1] while the second direction Dy = [[1], [-1]]. When we convolve the image with these kernel, we would get the following results. Then using the magnitude function (sum(square dx + square dy) then square root) we can find the gradient magnitude as shown. Lastly, we will also threshold the magnitude image to reduce noises.

Image 1 for Part 1.1
Original
Image 2 for Part 1.1
Dx
Image 3 for Part 1.1
Dy
Image 2 for Part 1.1
Equation From Lecture
Image 2 for Part 1.1
Magnitude
Image 3 for Part 1.1
Threshold

Part 1.2: Derivative of Gaussian (DoG) Filter

Instead of directly applying our dirivative kernal, we now first low pass filter our original image (blur) before we apply the dirivative kernal.
What differences do you see?
The results we get seems to reduce noise a lot better. The edge lines are more clear (thicker).

Image 1 for Part 1.1
Original
Image 2 for Part 1.1
blur
Image 3 for Part 1.1
dx_blur
Image 3 for Part 1.1
dy_blur
Image 1 for Part 1.1
Magnitude
Image 2 for Part 1.1
Threshold

Lastly, we first apply the gaussian to the kernal and convolve them. The result of this we will call it as DoG. Then we apply the convovled kernals to the original image.
We now can verify that we get the same result as before. We can see the result filtered image is identical to the previous one we see. This shows that convolution is an associative operation.

Image 3 for Part 1.1
Gaussian
Image 1 for Part 1.1
dy_filter
Image 2 for Part 1.1
dx_filter
Image 3 for Part 1.1
Convolved
Image 1 for Part 1.1
Filtered

Part 2.1

In this section we will use the low pass filter to find the low frequencies. By subtracting the low frequencies form the image, we will then have the high frequencies. We will enhance the high frequency image and add it back to the original image to sharpen it. There is a mathematical simplification for this process. Essentailly we can create one single mask such that when we directly convolve with the image, the sharpening process as described will be performed. I show both result of taking the long process and compared it to unsharp mask filter enhancement. You can see that the results are essentailly the same.

Image 3 for Part 1.1
Unsharp Mask Filter

Image 3 for Part 1.1
Original
Image 1 for Part 1.1
Low Frequency
Image 1 for Part 1.1
High Frequency
Image 1 for Part 1.1
Sharpened Result
Image 1 for Part 1.1
Unsharp Mask Filter Result

Now, to make this more interesting, I would first intentionally blur an image. From that image, I would then run it through the enhancement process to see if we can get back something that looks as sharp as the original. The results show that the sharpened image actually turned out to be as sharp as the original non-blured image!

Image 3 for Part 1.1
Original
Image 3 for Part 1.1
Initial Blur
Image 1 for Part 1.1
Low Frequency
Image 1 for Part 1.1
High Frequency
Image 1 for Part 1.1
Sharpened Result
Image 1 for Part 1.1
Unsharp Mask Filter Result
Image 3 for Part 1.1
Original
Image 3 for Part 1.1
Initial Blur
Image 1 for Part 1.1
Low Frequency
Image 1 for Part 1.1
High Frequency
Image 1 for Part 1.1
Sharpened Result
Image 1 for Part 1.1
Unsharp Mask Filter Result

Part 2.2: Hybrid Images

For this section we will create hybird images which when look from far and close will show different results.

Image 1 for Part 1.1
Original 1
Image 1 for Part 1.1
Low Freq 1
Image 1 for Part 1.1
Original 2
Image 1 for Part 1.1
High Freq 2
Image 1 for Part 1.1
Blended

Let's look at the Fourreier analysis on one of these sets of pictures

Image 1 for Part 1.1
Original 1
Image 1 for Part 1.1
Low Freq 1
Image 1 for Part 1.1
Original 2
Image 1 for Part 1.1
High Freq 2
Image 1 for Part 1.1
Blended
Image 1 for Part 1.1
Original 1 Fourier
Image 1 for Part 1.1
Low Freq 1 Fourier
Image 1 for Part 1.1
Original 2 Fourier
Image 1 for Part 1.1
High Freq 2 Fourier
Image 1 for Part 1.1
Blended Fourier

This one didn't work out. I believe it is due to the fact that original 2 has strong backgroud lines. When taking the high frequency of it, it seems to dominate the lower frequency portion of image.

Image 1 for Part 1.1
Original 1
Image 1 for Part 1.1
Low Freq 1
Image 1 for Part 1.1
Original 2
Image 1 for Part 1.1
High Freq 2
Image 1 for Part 1.1
Blended
Image 1 for Part 1.1
Original 1
Image 1 for Part 1.1
Low Freq 1
Image 1 for Part 1.1
Original 2
Image 1 for Part 1.1
High Freq 2
Image 1 for Part 1.1
Blended

Part 2.3 and 2.4: Gaussian and Laplacian Stacks With Multiresolution Blending

In this part we will show the process of blending an orange and an apple using Gaussian and Laplacian stacks with the following procedure.
1. Take an image and create a Gaussian stack by continuing convolve with Gaussian.
2. Create Laplacian stack by taking the differences of the Gaussian stack. Append the last element of Gaussian stack onto the Laplacian stack.
3. Take a mask and create a Gaussian stack for it.
4. For each element in the Laplacian stack, multiply it with the mask. This will result in an array of masked Laplacians.
5. Repeat steps 1 to 4 with another image and a mask that is the negative of the one of step 4.
6. Take the two masked Laplacian stacks, add them element-wise to get a blended stack.
7. Collapse the blended stack by summing all the element in the stack to get a blended image.

Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1

Besides the Orange Apple Example, I also played around with some of other images.

Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1

Irregular Shapes

Lastly, we have to perform the same blend with iregular shapes. I created the iregular masks through an online drawing tool and convert it to a binary mask in python.

Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1
Image 1 for Part 1.1