CS 194-26 Project 2

Jaiveer Singh

Fun with Filters

Finite Difference Operator

The Finite Difference Operator is a simple filter that can be used to find the X and Y derivatives of a 2D image. Consisting of exactly one positive and one negative term of equal magnitudes, the finite difference filters function as high-pass filters. Only regions of high change persist after the filter has been applied, since only these areas of high change have a nonzero derivative.

Since parital derivatives are taken necessarily in a specific direction, it is often desired to combine the two individual derivative images into an overall plot. This can be accomplished via the gradient magnitude, which uses the L2-norm to show the magnitude of the overall gradient at each pixel.

After the magnitude of the gradient is determined for each pixel, a final step of thresholding and binarizing can be used to produce a relatively clean output of all of the edges in the image. After some tuning, a threshold of 72 out of an absolute pixel value of 255 was used to select only the most important foreground edges, while omitting noise.

Input Derivative in X Derivative in Y Gradient Magnitude Binarized Edges

Derivative of Gaussian

Instead of simply binarizing, another way we can eliminate the noise is by applying a low-pass filter to remove high frequencies. In image terms, applying the low-pass filter is equivalent to blurring with a Gaussian filter.

Blurring the cameraman image before continuing produces the following output sequence. The kernel employed here is a 5x5 Gaussian with sigma of 10. A much lower threshold of 22 is necessary, since the Gaussian filter reduces the peak values of edges.

Input Blurred Derivative in X Derivative in Y Gradient Magnitude Binarized Edges

There is a visible difference in the thickness of the edges, since the blurring filter effectively "fattens" any edge by the size of the filter. Additionally, the small artifacts in the background are now cleanly removed due to the removal of the underlying high frequencies.

Based on the fact that the convolution operator is commutative, we can combine the finite difference filters and Gaussian filter into a pair of "precomposed" filters, requiring only one large convolution across the entire image. The results, as shown below, are identical:

Input Derivative in X Derivative in Y Gradient Magnitude Binarized Edges

The actual precomposed filters are shown below. Note that the large sigma in this filter makes the overall Gaussian shape of the image more difficult to discern.

DoG in X DoG in Y

Fun with Frequencies

Image Sharpening

Artificially sharpening an image can be accomplished by increasing the amplitude of the high frequency signals, thus appearing as if the image is sharper to the human eye.

One approach to do this is a straightforward application of steps. Begin by blurring the image and thus extracting only the low frequencies of the image. Subtracting the low frequencies of the image from the original image leaves only the high frequencies. Combining the low frequencies with a scaled multiple of the high frequencies produces a "sharpened" image.

Input Low Frequencies High Frequencies Sharpened

For efficiency, we can actually combine all of these steps into a single convolution, called the "unsharp mask filter". This filter is composed as `(1+alpha)*e - alpha*g`, where `e` is the Unit Impulse and `g` is the Gaussian kernel. The outputs look the same as the original method.

Input Low Frequencies High Frequencies Sharpened

Blurring and resharpening an already-sharp image of Prof. Efros produces results that seem passable in isolation, but pale against the true image. This is because the true highest frequencies were totally removed by the low pass filtering step, and could never be recovered.

Examining the square on the shirt is a good reference point.

Input Blurred Resharpened

Hybrid Images

An additional exploration with frequencies is to blend two images together by combining their frequencies - one image contains high frequencies, while the other contains low frequencies only. Then, the distance from the image affects the perception.

An example on the classic combination of human and cat is shown below:

Human Cat Combined

An additional hybrid with a basketball and a football is shown below:

Football Basketball Combined

A frequency analysis of the basketball-football hybrid is shown below:

Basketball FFT Basketball FFT Filtered Football FFT Football FFT Filtered Combined

An earlier attempt combining Obama with The Rock was best categorized as a failure. Even though the head positions are similar, the arrangement of the eyes and the area of focus of each subject differs, which produces eery and uncanny results in combination. Thus, even though the effect is successful, the overall result is not something worth celebrating.

Obama The Rock Combined

Image Blending

This section leverages a better technique for blending in a way that hides the seam between the two images. This can be accomplished using a combination of Laplacian and Gaussian stacks of both half-images and the mask joining the two.

We can see the results on the classic 'oraple':

Apple Orange Oraple Mask Oraple

A glimpse into the Laplacian and Gaussian stacks used to compose this image is shown below.

Apple Orange Oraple

Finally, a few examples using other masks with other images are shown below:

Fall Spring Sprall Mask Sprall

Also, Obama and the Rock are successfully combined in the end!

Obama The Rock Obock Mask President Obock The Robama Johnson