🐈

CS180 Project 2: Fun with Filters and Frequencies!

Author: Nicolas Rault-Wang (nraultwang at berkeley.edu)

Credit to Notion for this template.

Part 1: Fun with Filters

  • In this part, we’ll take x and y partial derivatives of the “cameraman” image, \ell\,, by convolving it with the finite difference filters DxD_x and DyD_y.
  • To see the effects of first applying a gaussian filter GG, we’ll take these partial derivatives of \ell without (part 1.1) and before (part 1.2) smoothing.
  • We’ll use the following notation:
=cameraman image matrix,Dx=[11],Dy=[11],G=2d gaussian filter with σ=2\ell = \text{cameraman image matrix}, \newline D_x = \begin{bmatrix}1&-1\end{bmatrix},\newline D_y = \begin{bmatrix}1\\-1\end{bmatrix}, \newline G = \text{2d gaussian filter with }\sigma = 2
Original “cameraman.png”

Part 1.1: Finite Difference Operator

Results of taking the partial derivatives of \ell (without smoothing).

Part 1.2: Derivative of Gaussian (DoG) Filter

Results of first smoothing \ell, then taking the partial derivatives.
Results of convolving \ell with the derivative of gaussian filters DxGD_x * G and DyGD_y*G.
Derivative of gaussian filters.

Part 2: Fun with Frequencies!

Part 2.1: Image "Sharpening"

Let \ell denote a given grayscale 2d image, α\alpha denote the sharpening parameter, and gg denote a gaussian filter, and δ\delta denote the unit impulse.

Starting from the given definition of the unsharp procedure, we apply the properties of convolution to simplify:

+α(g)=δ+α(δg)=δ+α(δ)α(g)=δ+(αδ)(αg)=((1+α)δαg)\begin{align} \ell + \alpha(\ell - \ell * g) &= \ell*\delta + \alpha(\ell*\delta - \ell * g) \\ &= \ell*\delta + \alpha(\ell*\delta) - \alpha(\ell * g) \\ &= \ell*\delta + \ell*(\alpha \delta) - \ell * (\alpha g) \\ &= \ell*((1 + \alpha)\delta - \alpha g) \end{align}

Hence, the unsharp filter h(1+α)δαgh \equiv (1 + \alpha)\delta - \alpha g can be applied with single convolution via h\ell * h.

Experiment: Sharpen an Image, Blur It, then Sharpen It Again

Part 2.2: Hybrid Images

Dr. Strangelove and President Muffley
Me + Savannah
Alter Ego
Oppenheimer
Barbenheimer 1
Barbenheimer 2
Stonks, Not Stonks

Input Images + Hybrid Result

Discussion: Colorizing Hybrid Images

Part 2.3: Gaussian and Laplacian Stacks

Masked Apple (left), Masked Orange (middle), and blended output (right).
Recreation of Figure 3.42 in Szelski (Ed 2) page 167.

Part 2.4: Multi-resolution Blending

Golden Gate Tabby
Barbenheimer
Venus on Earth, Brought to You by Big Oil
Moon Cat Discovers Earth

Input Images + Blended Result

Discussion: Creating “Golden Gate Tabby

Golden Gate Tabby, an output of our multi-resolution blending procedure.

In this section, we’ll add an orange tabby cat to the Golden Gate Bridge to illustrate our process of blending two images together with an irregular mask.

Step 1: Select and Preprocess Images

Image A serves as the background
Image B contains the subject to be blended into Image A.
  1. Select a large image A to serve as the scene. In this case, A is a photo of the Golden Gate Bridge.
  1. Find a smaller image B satisfying the following conditions:
    1. B has dimensions no larger than A. (Cropping may be needed.)
    1. The subject in B can be easily separated from the background.
  1. Optionally crop or scale images A and B.
  1. Zero pad B to the dimensions of A.
  1. Use np.roll to adjust the position of B on A until a good alignment is achieved.
    1. These adjustments can be fine-tuned by plotting A+BA + B^\prime, where BB^\prime is B after rolling.
    1. There will likely be an ugly rectangle around the object in image B that we will next remove in the next step.

Step 2: Create a Mask

  1. Select a threshold
    1. Our method for computing a good threshold involves computing statistics the maximum, minimum, sum, or mean of the color channel values at each pixel (i,j)(i,j), then choosing a percentile cutoff of these values to serve as a binary threshold.
    Mask with threshold set to 3 (pure white).
    Mask with threshold 2.94determined the 23rd percentile of color channel sums.
    Mask with threshold 2.847determined the 23rd percentile of color channel maximums.
  1. Zero-pad the mask to the dimensions of A.
  1. Apply the same displacement found in step 1e to this mask.

Step 3: Multi-resolution Blending

What I Learned from This Project

This project taught me intuition about what 2D frequencies are and how they affect our perception of images. My work creating hybrid images was particularly enlightening because it gave me first-hand experience with human vision’s contrast-sensitivity curve: I could control the strength and believability of the hybrid effect just by adjusting the high- and low-frequency spectral content from each images.