Fun with Filters and Frequencies!

Henley Zhang
September 21, 2024

Introduction

emir

In this project, we explore different applications of using frequencies to process images in interesting ways. First, we process the images in different ways for edge detection, using finite difference or Derivative of Gaussian Filters. We then explore the separation of an image into high and low frequencies to create sharpen filters, combine images into hybrid images, and develop combine images through gaussian and laplacian pyramids.

Part 1: Fun with Filters

1.1 Finite Difference Operator

Approach

We take the partial derivative of the image by convolving the image with the finite difference, dx = [1, -1] and dy = [[1], [-1]] vertically. To develop edges, we binarize the image by thresholding a value and setting to black or white accordingly We use these derivatives to create a gradient magnitude image which shows the edges, using np.sqrt(dx ** 2 + dy ** 2).

dx

dx filter

dxb

dx filter (binarized)

dy

dy filter

dyb

dy filter (binarized)

gradient

gradient magnitude image

gradientb

gradient magnitude image (binarized)

We found that the optimal threshold for the binarization was 50

1.2 Derivative of Gaussian Filter

Blurred Approach

We first repeat 1.1 on the image that has been convolved with a Gaussian kernel to blur it. We found a good kernel parameter was k = 10, sigma = 2

bdx

Blurred dx filter

bdxb

Blurred dx filter (binarized)

bdy

Blurred dy filter

bdyb

Blurred dy filter (binarized)

bgradient

Blurred gradient magnitude image

bgradientb

Blurred gradient magnitude image (binarized)

I notice that in these images much of the noise has been removed, which results in cleaner edges. The edges themselves are also thicker

Derivative of Gaussian Filter Approach

We first convolve the gaussian kernel with dx = [1, -1] and dy = [[1], [-1]] respectively to create two DoG filters. We then convolve the original image with these filter to create the dx and dy blurred. Again, the gradient is calculated

dogdx

DoG dx filter

dogdxb

DoG dx filter (binarized)

dogdy

DoG dy filter

dogdyb

DoG dy filter (binarized)

doggradient

DoG gradient magnitude image

doggradientb

DoG gradient magnitude image (binarized)

The images are virtually identical.

Part 2: Fun with Frequencies

2.1 Image Sharpening Approach

The image is convolved with the gaussian kernel to blur it, which removes the high frequencies. We then subtract the blurred image from the original to have just the high frequencies. We then add this back to the original image to sharpen it, multiplied by an alpha to boost sharpness.

taj

Original Image

tajg

Image Details (high frequencies)

tajs

Sharpened Image

tajs2

Original Image

tajg2

Image Details (high frequencies)

tajs2

Sharpened Image

Blurred, then resharpened.

Here we blurred the image, only to sharpen it again to compare

oblur

Original Image

oblur

Blurred Image

oblur

Image Details (high frequencies)

oblur

Resharpened Image

2.2 Hybrid Images Approach

We create hybrid images. We first apply Gaussian blur to one image to get the low frequencies. We then get the high frequencies of the other image by subtracting the original from the blurred. We then add the low frequencies from image one to the high frequencies of image two, to create the hybrid image.

low

Hybrid Image Result

low

FFT frequency analysis

fft

FFT of the image

fft2

FFT of the result image

fft3 fft4 fft5 fft6

This drake one was a bit of a failure. I could not get the images to align in a way where it was difficult to see the low frequency image even when close up. It was also too easy to see the high frequency image when view from far away.

2.3 Gaussian and Laplacian Stacks

A gaussian stack was constructed by repeatedly convolving the image with a gaussian kernel, blurring the image without downsampling. The laplacian stack was constructed by taking the difference between the i and i + 1 for i in the gaussian stack, capturing the loss in detail in each level of the gaussian stack.

gauss

Gaussian Stack

lap

Laplacian Stack

lap

Gaussian Stack

lap

Laplacian Stack

For these preview images, the images were normalized so that it can bee seen with the eye.

2.4 MultiResolution Blending

Image 1 and Image 2 are used to generate laplacian stacks. Then, a gaussian stack is created from the mask image. TO create the blended image, this formula was used (1 - mask_gaussian _stack[i]) * laplacian_stack1[i] + mask_gaussian_stack[i] * laplacian_stack2[i] = blended_stack[i] Then the blended image is reconstructed by summing the blended stack.

blend

Pre Blended Image

blend blend
Here I tried to get the best result possible, with 100 layers, kernel of 5, 500, which took 10 min. The seam is barely reduced
blend blend

Pre Blended Image 1

blend

Pre Blended Image 2

blend

Blended Image

blend

Pre Blended Image 1

blend

Pre Blended Image 2

blend

Mask Image

blend

Blended Image