Programming Project #2 (proj2)
Fun with Filters and Frequencies!
Name: Daniel Edrisian
SID: 3033649753
Email: edrisian@berkeley.edu
All the code for this project is located in main.py
--aside from the image aligning, which is in align_image_code.py
. The input images are sorted in /inputs
and output images are sorted in /outputs
.
Table of contents:
Part 1: Fun with Filters
Part 1.1: Finite Difference Operator
We start by generating edges for the cameraman picture using gradient magnitude computation. The way it works is by first generating the the horizontal derivative of the image, followed by the vertical derivative of the image, and then by taking the square root of the sum of squares of both deritvatives, just like how you compute the pythagorean theorem. This way, the negative values in each derivative image will turn into positives and you will be left with an image where edges are all colored white.
Then, we binarize the gradient magnitude in order to remove a lot of the noise within the image:
Gradient magnitude |
Binarized |
|
|
Part 1.2: Derivative of Gaussian (DoG) Filter
There's some noise, so lets fix it. First, we try to blur the image before doing what we did in the last part. The results are as follows:
Original |
Blured |
|
|
Gradient magnitude |
Binarized |
|
|
Then, instead of applying a gaussian blur and then the derivatives as two convolutional operations, we convolve the gaussian by the derivatives so that the whole operation is done in one convolution on the image. As we can see, the results are (almost) the same, so it's better to do the DoG way.
Derivative of gaussian Dx |
Derivative of gaussian Dy |
|
|
Dx result |
Dy result |
|
|
Gradient Magnitude |
Binarized |
|
|
Part 2: Fun with Frequencies!
Part 2.1: Image "Sharpening"
We use un-sharp masking in order to sharpen the following images. We do it by taking the high freq of an image and adding it to the image multiplied by a factor.
Sharpen Taj Mahal
Original |
Sharpened (alpha = 1.5) |
|
|
Sharpen Dog
Original |
Sharpened (alpha = 1) |
|
|
Blur image, then sharpen
I tried to blur a sharp image, then sharpen it back to see what happens. The result is a grainy image that has smaller blured edges, but still fails to be as sharp as it was before. I even tried an alpha factor of 15 whih is huge, but it still couldn't do much.
Original |
Blured |
Sharpened (alpha = 15) |
|
|
|
Part 2.2: Hybrid Images
In this part, I layer two images on top of each other so that in distance it appears as one, and close up it appears as the other. The images are first aligned so they match each other's geometries. For the first image, the lower frequencies are use and they are grayscaled. For the second image, the higher frequencies are used with their color.
Derek and Nutmeg
Derek |
Nutmeg |
|
|
Derek Aligned |
Nutmeg Aligned |
Nutmeg over Derek |
|
|
|
The fourier results of the images are shown below:
Derek FFT |
Derek Blur (low frequencies) FFT |
|
|
Nutmeg FFT |
Nutmeg high frequencies FFT |
Combination Derek + Nutmeg FFTs |
|
|
|
Airplane and Eagle (Failure)
Because the eagle has a much larger and much darker wing than the plane, it isn't as smooth as the other results. It's obvious that two images are layer on each other. Other than that, the tips look good.
Airplane |
Eagle |
|
|
Airplane Aligned |
Eagle Aligned |
Eagle over Airplane |
|
|
|
John DeNero and Josh Hug
This is my favorite.
Airplane |
Eagle |
|
|
Airplane Aligned |
Eagle Aligned |
Eagle over Airplane |
|
|
|
Multi-resolution Blending and the Oraple journey
Part 2.3: Gaussian and Laplacian Stacks
Here, we try to blend an apple and orange together. We use basic alpha blending where the images start smoothly reducing in alpha in the middle, so that they can be added on top of each other and appear as if they go into each other.
Apple |
Orange |
|
|
The following is the stack the closely resembles the figure in the original paper. Rows 1, 2, and 3 show the 0th, 2nd, and 4th laplacians of the apple, orange, and the apple-orange blend. The last row is just the original images alpha blended.
Level |
Apple |
Orange |
Apple and Orange |
0th Laplacian |
|
|
|
2nd Laplacian |
|
|
|
4th Laplacian |
|
|
|
Original |
|
|
|
Part 2.4: Multiresolution Blending (a.k.a. the oraple!)
To improve on the blending, we settle on a better algorithm that combines each level of the laplacians in the stacks and adds it on top of the lowest gaussian blur. This results in smooth blends between images that appear real. The algorithm is taken from the original paper.
The Oraple
Apple |
Orange |
|
|
Level |
Apple Gaussian |
Apple Laplacian |
Orange Gaussian |
Orange Laplacian |
0 |
|
|
|
|
1 |
|
|
|
|
2 |
|
|
|
|
3 |
|
|
|
|
4 |
|
|
|
|
Level |
Laplacian Blend |
Mask |
0 |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
Sun in a Sunflower
Brain in a walnut (favorite)
Brain |
Walnut |
|
|
Level |
Brain Gaussian |
Brain Laplacian |
Walnut Gaussian |
Walnut Laplacian |
0 |
|
|
|
|
1 |
|
|
|
|
2 |
|
|
|
|
3 |
|
|
|
|
4 |
|
|
|
|
5 |
|
|
|
|
Level |
Laplacian Blend |
Mask |
0 |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
Conclusion
This was a wild project. It really makes you appreciate how many layers there are to a single image and just what you can do with super basic filters--not even transformations. Overall I would highly recommend it to anyone.