Project 2

Part 1: Fun with Filters

Build intuition about 2D convolutions and filtering!
cameraman

Finite Difference Operator

I use finite difference operations to show the partial derivative in x and y of the cameraman image by convolving the image with the operators. Then I compute the gradient magnitude image. Finally, I turn this into an edge image by picking the appropriate threshold from the gradient magnitude. $$ D_x = \left[ 1 \ -1 \right], \quad D_y = \left[ \begin{array}{c} 1 \\ -1 \end{array} \right] $$ $$ C_x = \text{cameraman} * D_x, \quad C_y = \text{cameraman} * D_y $$ $$ G_m = \sqrt{{C_x}^2 + {C_y}^2}, \quad G_e =\begin{cases} 1 & \text{if } G_m > 0.2 \\ 0 & \text{otherwise} \end{cases} $$

Derivative X
$$ C_x $$
Derivative Y
$$ C_y $$
Gradient(mag)
$$ G_m $$
First Image
$$ G_e $$

Derivative of Gaussian (DoG) Filter

We noted that the results with just the difference operator were rather noisy. Luckily, we have a smoothing operator handy: the Gaussian filter G. Here, I create a blurred version of the original image by convolving with a Gaussian (width=5 and SD=1) and repeat the procedure in the previous part.

Derivative X
$$ C_x $$
Derivative Y
$$ C_y $$
Gradient(mag)
$$ G_m $$
First Image
$$ G_e $$
Much less noisy! Derivatives are much stronger, which results in a clearer and thicker final edge detection.

Now we can do the same thing with a single convolution instead of two by creating a derivative of gaussian filters.

$$ G_x = \frac{d}{dx} G, \quad G_y = \frac{d}{dy} G $$

Derivative X
$$ G_x $$
Derivative Y
$$ G_y $$

Derivative X
$$ C_x $$
Derivative Y
$$ C_y $$
Gradient(mag)
$$ G_m $$
First Image
$$ G_e $$
They are the same! Except now we saved one operation...

Part 2: Fun with Frequencies!

Image "Sharpening"

Unsharp masking technique:
  1. Use Gaussian as a low pass filter to blur image.
  2. Extract high frequencies from an image by subtracting the blurred version from the original image.
  3. Apply unsharp mask filter by adding $$ \alpha * high frequencies $$ to the original image.

Alpha 0
$$ \alpha=0 $$
Alpha 1
$$ \alpha=1 $$
Alpha 2
$$ \alpha=2 $$
Alpha 5
$$ \alpha=5 $$
Alpha 10
$$ \alpha=10 $$

Alpha 0
$$ \alpha=0 $$
Alpha 1
$$ \alpha=1 $$
Alpha 2
$$ \alpha=2 $$
Alpha 5
$$ \alpha=5 $$
Alpha 10
$$ \alpha=10 $$

Alpha 0
$$ \alpha=0 $$
Alpha 1
$$ \alpha=1 $$
Alpha 2
$$ \alpha=2 $$
Alpha 5
$$ \alpha=5 $$
Alpha 10
$$ \alpha=10 $$

Blurring then sharpening an image ("sanity check").

Derivative X
Agama
Derivative Y
Agama Blurred

Alpha 0
$$ \alpha=0 $$
Alpha 1
$$ \alpha=1 $$
Alpha 2
$$ \alpha=2 $$
Alpha 5
$$ \alpha=5 $$
Alpha 10
$$ \alpha=10 $$
The original agama compared to the blurred then sharpened agama does a decent job, but obviously has some errors. With alpha=2, the edges look realistic but it's not sharpened enough – we lose a lot of the details on the agama scales. For alpha=5, we do a much better job of getting the details of the scales, but now there is more noise in the image. For example, we are now hallucinating some colors. Around each scale, there is some orange hue that did not exist in the original image. The borders are also no longer smooth like alpha=2.

Hybrid Images

Efros
Low Frequency
Dog
High Frequency
Hybrid
Close
Hybrid
Afar
Shocked
Low Frequency
Frown
High Frequency
Hybrid
Close
Hybrid
Afar
Failure?
Shocked
Low Frequency
Frown
High Frequency
Hybrid
Close
Hybrid
Afar
The potato can be seen too much in the close up, whereas leprechaun's appears too shadowy. Better alignment will most likely fix this issue, specifically shrinking the potato to be behind the leprechaun.

Favorite!!!

Efros
Low Frequency
Dog
High Frequency
Hybrid
Close
Hybrid
Afar

Frequency Analysis

Efros
Log FFT(Efros)
Dog
Log FFT(Dog)
Hybrid
Log FFT(Low Frequency of Efros)
Hybrid
Log FFT(High Frequency of Dog)
Hybrid
Log FFT(Hybrid)

Bells & Whistles

Trying to use color to enhance the effect. I tried four experiments using my favorite set of images, Efros and the dog. I tried using (1) black and white for both frequency components, (2) color only low-frequency component (3) color only high-frequency component, and (4) both in color.

Efros
Both B/W
Dog
Low Frequency in Color
Hybrid
High Frequency in Color
Hybrid
Both Color
Efros
Both B/W
Dog
Low Freq. Color
Hybrid
High Freq. Color
Hybrid
Both Color
I think all results look pretty good! I prefer the both color simply just because we can keep the color, so I generate the rest of the images above fully in color. It is interesting though, that in B/W we can hide the glow/shadowy effect that happens in the colored versions.

Gaussian and Laplacian Stacks

Algorithm for blending two different images:

  1. Build Gaussian stack for both images: $$ G^A, G^B $$.
  2. Build Laplacian stack for both images: $$ L^A_i = G^A_i - G^A_{i+1}, \quad L^B = G^B_i - G^B_{i+1 }$$
  3. Add the lowest frequency of the Gaussian stack to the end of both Laplacian stacks.
  4. Build Gaussian stack for mask: m.
  5. Build a combined Laplacian stack L such that: $$ L_k = L_k^A \cdot m_k + K_k^B \cdot (1 - m_k)$$
  6. Collapse L to obtain the blended image.

Blending an apple with an orange!

Dog
Apple
Hybrid
Orange

Apple Gaussian Stack

Dog
Hybrid
Hybrid
Hybrid
Hybrid

Apple Laplacian Stack

Dog
Hybrid
Hybrid
Hybrid
Hybrid

Orange Gaussian Stack

Dog
Hybrid
Hybrid
Hybrid
Hybrid

Orange Laplacian Stack

Dog
Hybrid
Hybrid
Hybrid
Hybrid

Recreation of Figure 3.42

Level 0

Dog
Hybrid
Hybrid

Level 2

Dog
Hybrid
Hybrid

Level 4

Dog
Hybrid
Hybrid
Collapsed
Dog
Hybrid
Hybrid

Multiresolution Blending

Example 1) Oraple!

Dog
Orange
Hybrid
Apple
Hybrid
Mask
Hybrid
Oraple

Example 2) Tree with an eye! (irregular mask)

Dog
Tree
Hybrid
Eyes
Hybrid
Mask
Hybrid
Oraple

Example 3) Shrek Mona Lisa! (irregular mask)

Dog
Mona Lisa
Hybrid
Shrek
Hybrid
Mask
Hybrid
Oraple

Example 4) Is it day or night?! (favorite)

Dog
Day
Hybrid
Night
Hybrid
Mask
Hybrid
Day or night?

This is my favorite result, and below are the Laplacian stacks generated during the blending process: (Fig. 10 recreation)

Level 0

Dog
Hybrid
Hybrid

Level 2

Dog
Hybrid
Hybrid

Level 4

Dog
Hybrid
Hybrid
Collapsed
Dog
Hybrid
Hybrid

Bells & Whistles

Added color to everything!!

Reflection

I had a lot of fun with this project. The most important thing I learned was that you can do so much with image processing just by playing around with frequencies :) And that Gaussians are super useful in the CV space.