Project 2 - Fun with Filters and Frequencies!

Anderson Lam (3033765427)

Overview

For this project, we learn how to use Gaussian and Laplacian filters/stacks to sharpen images, detect edges, and blend images together. We will also attempt to perform what many modern camera software can do today - straighten images!

Part 1: Fun with Filters

Part 1.1: Finite Difference Operators

For this part of the project, we should the partial derivative in x and y of the cameraman image with convolutions. We utilize the finite difference operators, dx = [1, -1] and dy = [1, -1].T. We take the image and convolve them with the finite difference operators. We then compute the gradient mangitude with the formula of magntidue = np.sqrt(x**2 + y**2). Afterwards we want to suppress noise by binarizing the magnitude. I tried to binarize with the canny filter as well as manually by using operators (lowThresh < img) & (img < upperThresh).

Original

dx, dy

Magnitude

binary threshold < .25, canny sigma = 3

Part 1.2: Derivative of Gaussian (DoG) Filter

For this part of the project, we want to reduce noise for the cameraman image by using a gaussian filter and then detect the edges. We take a 1D Gaussian from cv2.getGassuianKernel() then take its outer product with its self to get a 2D version. I used a kernl size of 8 and sigma of 2. Below are the resulting images. Differences I see are that the detected edges are wider after the Gaussian bluring and also less noise in the image with thicker lines since the Gaussian filter made the pixels surrounding edges inherit the values from the true edges.

kernel 8x8 sigma 2 dx, kernel 8x8 sigma 2 dy

dog dx, dog dy

dog magnitude, dog magnitude binarized (> .08)

Part 1.3: Image Straightening

For this part of the project, we are rotating the images, cropping the image (to remove noisy artifacts), calculating the gradient angles and producing the desired angle that has the gradient angles closest to horizontal and vertical edges. I did try to use the Fourier domain, but it did not work as well with my method. Some images may be harder to straighten with the heuristic I made since the angles may be more random. For my gradient angles histogram, I ignored angles extremely close to pi/2 multiples (i.e. < 0.05 rads).

facade original

facade straight (-3 rotation)

amy plant original

amy plant straight (-5 rotation)

bench original

bench straight

seattle2 original

The straightening for the image did not work well as can be easily indicated by the cloud. This is because the many roofs of the buildings are not straight and that is being aligned as straight as possible.

seattle2 straight (-8 rotation)

Part 2: Fun with Frequencies!

Part 2.1:Image "Sharpening"

For this part of the project we attempt to sharpen images artificially but adding another layer of detail to our images. We get this layer of detail by bluring our image and the subtracting our originaly image by that blurred image. We then add back this detail layer to the original image. This is the unsharp masking technique. We use the single convolution operation. I included color by applying the Gaussian blur on the 3 different channels then stacking it. I used a Gaussian filter of size 5 and sigma of 1.

detail = original - blur

final = original + detail

original, blur, detail (alpha = 1), sharpened

seattle original, blur, detail (alpha = 1), sharpened

Justin Timberlake original, blur, detail (alpha = 1), sharpened

Part 2.2: Hybrid Images

For this project we utilize low pass and high pass filters to merge images. With the starter code, we can align the photos then applying the filters. I added color by running the low anad high pass filters on the 3 color channels for each image and stacked them together. I also kept color for the low or high freq img.

Derek (low) and Nutmeg (high), used Gaussian sizes of 50 and sigma values of 1 (low) and 8 (high)

low, fft, high, fft

hybrid image, fft

colored, fft of colored, color low-only, color high-only

After comparing the colored and noncolored version. I would say that having color can definitely help with blending if the colors are pretty similary. Having the low pass filter image with only color is too ovepowering and the high pass filter image with color is more netural.

Anderson (low) and Amy (high), used Gaussian size 50 and sigma values of 1 (low) and 8 (high)

hybrid image, fft

colored, color low-only, color high-only

Brittany (low) and Anderson (high), used Gaussian size 50 and sigma1 = 1 and sigma2 = 8

hybrid image, fft

f

colored, color low-only, color high-only

Lion (low) and Bear (high), used Gaussian size 50 and sigma1 = 1 and sigma2 = 8

hybrid image, fft

colored, color low-only, color high-only

Part 2.3: Gaussian and Laplacian Stacks

For this part of the project we generate Gaussian and Laplacian stacks. My Glaussian filter size is 50 here with an increasing sigma of 2 starting at 2 (i.e. 2, 4, 6, 8, 10).

Lincoln, top = Gaussian, bottom = Laplacian

amyanderson from hybrid image, top = Gaussian, bottom = Laplacian

EinsteinMonroe, top = Gaussian, bottom = Laplacian

Part 2.4: Multiresolution Blending

For this part of the project we attempt to blend two images seamlessly using a multires blending solution. We do this by creating a mask filter and applying Gaussian and Laplacian stacks on the mask and the two images we want to blend. The idea is to sum up the images on each level like mask * image1 + (1 - mask) * image2. For color, we apply this technqiue on each of the 3 color channels then stack them together like in project 1.

Orapple

unblended, blended, blended color

Having the colored images definitely help with the blending much better as it can show more difference in detail after the blending.

Autumn + Spring + Mask Used

blended, blended color

Obama + George

unblended, blended, blended color

Gaussian/Laplacian Process with Mask

Orapple V2

blended, mask, blended color

IRREGULAR MASK

For this portion, I decided to put myself in a new place so it is like I "traveled" there.

blended, blended color

Extras

For the bells and whistles, I managed to add color to the hybrid images (or specify low or high freq for color) and I also added color to the multiresolution blending images with masks. I achieved this by simply processing the images 3 times for their 3 channels then I stacked them together. Colors definitely help for differentiating between details and making something look even cooler or amazing.

This coolest thing I learned from this assignment is definiteley how the straightening software might work as well as how we can blend image together pretty easily with the Gaussian/Laplacian images. The math did seem intimidating at first, but after thinking more deeply about how the images work together it made a lot of sense. As for creating a herustic for the image straightening, it was also pretty challenging and I hope to learn more about other types of metrics that we could use.

The most important thing I learned about this project is that there are so many things you can do with an image's data and we can continue to do a lot with computational photography. Another thing for me would be to just start thinking the bigger picture about what I want to achieve and the things I can measure or look at to do so. This project seemed extremely challenging but proved to be very rewarding.