Programming Project #2 (proj2)

Fun with Filters and Frequencies

Fun with Filters and Frequencies!

Part 1: Fun with Filters

Part 1.1: Finite Difference Operator

In this section, we use finite difference operators \( D_x \) and \( D_y \) to compute the gradients of the image, thereby extracting edge information.

Original Image
Original Image
  1. Gradient Computation:
  2. p1_1_dx_image.png
    Derivative Dx
    p1_1_dy_image.png
    Derivative Dy
  3. Gradient Magnitude Image:
  4. gradient_magnitude Image
    Combined Gradient
  5. Binarization Processing:
  6. binarized Image
    Combined Binarized

Part 1.2: Derivative of Gaussian (DoG) Filter

Firstly, we convolve the image with a Gaussian filter to obtain a blurred image. The Gaussian filter is a smoothing filter that can effectively remove high-frequency noise in the image, making the image smoother.

p1_2_blur_image
Blur Image
blur_image_dx
Blur Image Derivative Dx
blur_image_dy
Blur Image Derivative Dy
gradient_magnitude_blur
Blur Image Combined Gradient

Next, we perform edge detection on the blurred image. This is different from directly performing edge detection on the original image in Part 1.1. By comparing the binarized edge images of these two methods, we can observe the following:

p1_1 binarized Image
Binarized edge image in Part 1.1 (without smoothing)
p1_2 binarized Image
Binarized edge image in Part 1.2 (after Gaussian smoothing)

We can find that the image processed by Gaussian smoothing performs better in edge detection because the smoothing process suppresses noise while retaining the main edge information.

In addition, there is another processing method, which is to convolve the Gaussian filter with \( D_x \) and \( D_y \) to obtain the Derivative of Gaussian (DoG) filters, and then convolve these DoG filters with the original image. This way, we can perform smoothing and edge detection in one convolution operation.

p1_2_DoG_x
Result of \(G * D_x\)
p1_2_DoG_y
Result of \(G * D_y\)
image_DoG_x
Result of \((G * D_x) * I\)
image_DoG_y
Result of \((G * D_y) * I\)
p1_2_gradient_magnitude_DoG
Derivative of Gaussian Combined Gradient

The mathematical principle of this process can be explained using the commutative property of convolution: $$ G * (D_x * I) = (G * D_x) * I $$ where:

G * (D_x * I)
\( G * (D_x * I) \)
(G * D_x) * I
\( (G * D_x) * I \)

This shows that convolving the image with the Gaussian filter first and then performing edge detection is equivalent to combining the Gaussian filter and the gradient operator first and then applying it to the original image. This method can reduce the computational cost of two convolutions and improve processing efficiency.

Part 2: Fun with Frequencies!

Part 2.1: Image "Sharpening"

In this section, our main goal is to sharpen the image. The basic principle of image sharpening is to enhance the high-frequency parts of the image, making the image look clearer and more detailed.

  1. Gaussian Smoothing:

    Firstly, use a Gaussian filter to smooth the image, which can remove some high-frequency noise in the image, making the image more blurred and smooth.

  2. taj
    Original Image of Taj Mahal
    Susuwatari
    Original Image of Susuwatari
    blur taj
    Blur Image of Taj Mahal
    blur Susuwatari
    Blur Image of Susuwatari
  3. High-Frequency Enhancement:

    Next, subtract the smoothed image from the original image to obtain the high-frequency parts of the image. This information contains the details and edges in the image.

  4. high freq taj
    High Frequency Image of Taj Mahal
    high freq Susuwatari
    High Frequency Image of Susuwatari
  5. Image Sharpening:

    Finally, add the high-frequency enhancement back to the original image to get the sharpened image. This process can make the details and edges in the image clearer, and the contrast will also be improved.

  6. sharpen taj
    Sharpen Image of Taj Mahal
    sharpen Susuwatari
    Sharpen Image of Susuwatari

Observations:

Taj Mahal Image
taj
Original Image of Taj Mahal
sharpen taj
Sharpen Image of Taj Mahal
Susuwatari Image
Susuwatari
Original Image of Susuwatari
sharpen Susuwatari
Sharpen Image of Susuwatari

Part 2.2: Hybrid Images

In this section, we will create hybrid images by combining different frequency components of two images. Such images will present different visual effects at different viewing distances:

  1. Frequency Separation:
  2. low_freq_image
    Low Frequency Image - Human Face
    high_freq_image
    High Frequency Image - Cat
  3. Cutoff Frequency:
  4. Hybrid Image Generation:
  5. hybrid_image
    Hybrid Image Human Face and Cat Face

Urban and Nature

Urban
Low Frequency Image - Urban
Nature
High Frequency Image - Nature
Urban and Nature
Hybrid Image

The Starry Night and Mona Lisa

The Starry Night
Low Frequency Image - The Starry Night
Mona Lisa
High Frequency Image - Mona Lisa
world_famous_painting
Hybrid Image

Frequency Analysis

  1. Frequency Analysis:
gray_image_1
Frequency of Urban
gray_image_2
Frequency of Nature
gray_image_low_freq_image
Frequency of Urban (low frequency)
gray_image_high_freq_image
Frequency of Nature (high frequency)
gray_image_hybrid_image
Frequency of the Hybrid Image

Part 2.3: Gaussian and Laplacian Stacks

In this section, we will implement Gaussian Stacks and Laplacian Stacks, which are important tools in multi-resolution image processing.

  1. Gaussian Stack
  2. Laplacian Stack

Demonstration:

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

In this section, we will use Gaussian and Laplacian Stacks to perform multi-resolution image blending, achieving seamless transitions between images.

Constructing Gaussian and Laplacian Pyramids

We need to construct the Gaussian and Laplacian stack for both images separately. Additionally, we need to build the Gaussian stack for the mask. The Gaussian stack captures the overall structure of the image, while the Laplacian stack retains the detailed information of the image.

Blending the Pyramids

At this stage, we blend the Laplacian stack of the two images using the Gaussian stack of the mask. Specifically, at each level, we apply the following formula:

\[ \text{Laplacian}_{\text{blend}} = \text{Laplacian}_{\text{image1}} \times \text{Gaussian}_{\text{mask}} + \text{Laplacian}_{\text{image2}} \times (1 - \text{Gaussian}_{\text{mask}}) \]

This formula means that the Gaussian stack of the mask is used to balance the Laplacian stack of the two images at each level. A higher mask value leans towards retaining the details of the first image, while a lower mask value leans towards retaining the details of the second image.

Reconstructing the Final Image

Finally, we start from the lowest level of the Laplacian image and progressively reconstruct the image level by level. At each level, we add the upsampled Laplacian image to the blended image, until we reach the original resolution. This gives us the final blended image.

oraple_stack
Oraple Stack
Oraple
Oraple
= Oraple
Your Name and Start