CS180: Project #2

by Adriel Vijuan

Fun with Filters and Frequencies

Introduction

In this project, I explored various image processing techniques, including finite difference operators, derivative of Gaussian (DoG) filters, image sharpening, hybrid images, and multiresolution blending using Gaussian and Laplacian stacks. These techniques were applied to several images, such as the Cameraman, Apple, Orange, and some custom images, to analyze their effects on edge detection, frequency domain manipulation, and image blending. The following sections provide a detailed report of the methods and results.

Part 1: Fun with Filters

1.1 Finite Difference Operator

In this part, I used finite difference operators to approximate the gradients in the x and y directions of the image, detecting edges based on changes in intensity.

Process:

The partial derivatives were computed using theseg formulas: \[ \frac{\partial I}{\partial x} = I * D_x \\ \frac{\partial I}{\partial y} = I * D_y \\ \nabla I = \sqrt{\left( \frac{\partial I}{\partial x} \right)^2 + \left( \frac{\partial I}{\partial y} \right)^2} \] Here, \( D_x = [1, -1] \) and \( D_y = [1, -1]^T \), and convolution \( * \) is applied between the image and the derivative operators.

Effectiveness:

To highlight the edges, a threshold was applied to the gradient magnitude image which filtered out noise and helped us to focus on prominent edges. The thresholding allowed for clearer depiction of edges, although fine-tuning was necessary to achieve the right balance.

1.2 Derivative of Gaussian (DoG) Filter

The finite difference approach produced noisy results, so to reduce noise and improve edge detection, a Gaussian blur can be applied to the image before calculating the gradients.

Process:

First, the image was smoothed using a Gaussian filter before applying the finite difference operators: \[ I_{\text{blurred}} = I * G \\ \frac{\partial I}{\partial x} = I_{\text{blurred}} * D_x \\ \frac{\partial I}{\partial y} = I_{\text{blurred}} * D_y \\ \nabla I = \sqrt{\left( \frac{\partial I}{\partial x} \right)^2 + \left( \frac{\partial I}{\partial y} \right)^2} \]

Effectiveness:

The Gaussian filter reduced noise and smoothed the image, leading to more refined edge detection. Additionally, by combining the Gaussian filter and derivative operators, I used Derivative of Gaussian (DoG) filters: \[ \text{DoG}_x = G * D_x, \quad \text{DoG}_y = G * D_y \] The DoG filters allowed for a more efficient and streamlined computation of edges, producing smoother results.

Key Findings:

The DoG method improved the clarity of edges, especially in regions with noise or minor intensity variations. The smoothing effect from the Gaussian filter helped to reduce noise while still highlighting key structural details in the image.

Part 2: Fun with Frequencies

2.1 Image Sharpening (Unsharp Masking)

Image sharpening enhances the edges and finer details in an image by increasing the presence of high-frequency components.

Process:

Using the unsharp masking technique, I first applied a Gaussian blur to the image, then subtracted the blurred version from the original to obtain the high-frequency details. The sharpening process is defined by: \[ I_{\text{sharpened}} = I + \alpha (I - I_{\text{blurred}}) \] The parameter \( \alpha \) controls the intensity of the sharpening effect.

Effectiveness:

When applied to slightly blurred images, this technique restored lost details effectively. However, when applied to already sharp images, over-sharpening resulted in noise amplification, making the image appear unnatural.

Key Findings:

Unsharp masking worked well in recovering details in blurry images. However, careful tuning of the sharpening factor \( \alpha \) is required to avoid over-sharpening, which can lead to unwanted noise.

2.2 Hybrid Images

Hybrid images combine the low-frequency components of one image with the high-frequency components of another. This technique creates a shift depending on the viewer's relative distance to the image: the high-frequency details dominate up close, while the low-frequency components become more obvious from further away.

Process:

The following steps were used to create a hybrid image: \[ I_{\text{low}} = I_1 * G, \quad I_{\text{high}} = I_2 - (I_2 * G) \] \[ I_{\text{hybrid}} = I_{\text{low}} + I_{\text{high}} \]

Custom Sigma Values: Effectiveness:

The hybrid images demonstrated a visual phenomenon where different images appeared based on the viewing distance. However, the two images being properly aligned was critical to the success of the hybrid image.

Key Findings:

While the hybrid technique produced good results, misalignment or incompatible features between the two images resulted in failure cases. Without a proper alignment of the images,it was difficult to achieve a smooth transition between the two frequency bands.

2.3 Gaussian and Laplacian Stacks

Gaussian and Laplacian stacks are key tools in multiresolution image analysis, allowing for smooth blending of images at different scales.

Process:

A Gaussian stack is created by repeatedly applying Gaussian filters to the image, resulting in progressively blurred versions: \[ \text{Gaussian Stack} = \{ G_0, G_1, G_2, \dots, G_n \} \] The Laplacian stack isolates the high-frequency components between consecutive levels of the Gaussian stack: \[ \text{Laplacian Stack} = \{ L_0, L_1, L_2, \dots, L_{n-1} \}, \quad L_i = G_i - G_{i+1} \]

Effectiveness:

By using these stacks, I could blend images at different resolution levels, ensuring smooth transitions between the images without visible artifacts.

Key Findings:

The Gaussian and Laplacian stacks were especially effective for image blending tasks, as they allowed for multiresolution analysis. This method enabled me to create seamless blends between different images across various frequency bands.

2.4 Multiresolution Blending

Multiresolution blending involves combining two images by blending their details at different scales. This technique uses Gaussian and Laplacian stacks to gradually blend images, resulting in a smooth transition between the two. By using a mask that transitions from one image to the other, we can control which parts of each image dominate in the final output.

Process:

The blending process consists of the following steps:

The following equations were used for blending: \[ \text{Blended Level}_i = \text{Mask}_i \cdot \text{Laplacian}_i(\text{Image1}) + (1 - \text{Mask}_i) \cdot \text{Laplacian}_i(\text{Image2}) \]

Custom Mask:

For this experiment, I used a simple horizontal mask where the left half of the mask was filled with 1s and the right half with 0s. This resulted in a smooth left-to-right transition between the two images that attempts to replicate the findings of the "spline83" paper.

Effectiveness:

The multiresolution blending technique enabled smooth, seamless transitions between two images by using a Gaussian mask to blend details at multiple scales, preventing abrupt changes or visible seams. This method is particularly effective for combining images with varying textures, lighting conditions, or focus areas. Additionally, fine-tuning the mask allows for creative control over the blend's smoothness and areas of influence.

Failure Case:

To address the failure case with my custom images, not every mask seemed to be compatible with my current Laplacian and Gaussian stacking, as the process is highly dependent on the images being used. Without proper fine-tuning of the mask and variables involved, the blend's smoothness can sometimes appear relatively rough.

Conclusion

This project gave me the chance to dive into various image processing techniques, from edge detection with finite difference and DoG filters to blending images using Gaussian and Laplacian stacks. Since I regularly use programs like Adobe Photoshop and Lightroom, it was really interesting to see the math and algorithms behind the tools I use every day. Understanding how different frequencies affect image clarity, detail, and blending helped me appreciate the concepts that make these software applications function.