CS 194-26Programming Project 2: Fun with Filters and Frequencies!


Author: Youqi Chen.

Part 1: Fun with Filters

In this part, I implemented programs with the ideas and techniques of filtering.

Part 1.1: Finite Difference Operator


In this section, I first get the partial derivative of the "cameraman.png" image by convoling it with D_x and D_y using scipy.signal.convolved2d. Then I obtained the gradient magnitude image from the square root of the sum of the squares of the derivatives computed in the first step. Finally, I use a threshold value of 0.1 to yield a binarized version of the gradient magnituede image. The real edges are well captured, but some noises at the bottom are not completed suppressed.

Part 1.2: Derivative of Gaussian (DoG) Filter

In this section, a 2D gaussian kernel is created with cv2.getGaussianKernel() and taking the outer product with its transpose convolved with original image to create a blurred version of the image before performing the same procedure in the previous part.

Differences: Edges more obvious and noises more suppressed.

Another try on this part is first finding the derivatives of the image and the gaussian and then convolve the derivetives to create a DoG filters. The result looks like the last result.

Part 1.3: Image Straightening

This section focuses on the auto-straightening of images. To maximize the number of vertical and horizontal edges, I used (-5, 5) as the set of proposed rotation, rotate, compute the angles in the image, and create a histogram of the angles. The rotation with the maximum number of horizontal and vertical edges are identified and applied to the original image to create a straightened version. There are a total of 4 examples, and the second one is a failure case.
Original Original Histogram Straightened Straightened Histogram

Part 2: Fun with Frequencies!

Part 2.1: Image "Sharpening"

The sharpening in this section is implemented by using the Gaussian filter (low pass) to create a low frequency image, subtract this image from the original image to get the high frequencies of the image, and add the high frequencies back to the original image.
Original Sharp

Below is an example of blurring a sharp image and then sharpening it again. The re-sharpened image is more blurry than the original because it takes it edges from the blurry image.
Original Blurred Resharpened

Part 2.2: Hybrid Images


In this part, I created the hybrid image by aligning based on 2 user input points and blending the high frequency part of the image with the low frequency part of the image so that it allows different interpretations at different distances. The low-pass filter is the standard 2D Gaussian filter and the high-pass filter is obtained by subtracting the gaussian filtered image from the original. The final blend is the average of the high pass edge image and low pass blurred image.

Input 1 Input 2 Hybrid

Frequency analysis: the log magnitude of the Fourier transform of the inputs, the filtered, and the hybrid images could be visualized below.

Part 2.3: Gaussian and Laplacian Stacks

In this part I implemented stacks with 5 levels. In the Gaussian stack, each level is generated by applying gaussian filter to the previous level. The Laplacian stack uses the output of the gaussian stack and getting each level by subtracting the current level from the level before.


Level 1 Level 2 Level 3 Level 4 Level 5

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

Overview

This part performs multiresolution Blending with 2 Laplacian stacks applied to the two input images respectively and 1 gaussian stack to the mask. Then using the formula in the paper to compute the blended image. Masks can have irregular shapes, as demonstrated in the flower and building examples.

Input 1 Input 2 Blended