Pixel Power (And other fun things)

William Keyes

Question 1

How can you remove high frequencies from an image?

There are two main ways to remove high frequencies from an image: lowpass filtering via convolution and lowpass filtering via Fourier tranforms. The original image is this cat in a toilet:

A cat lying in a toilet bowl

Picture by recubejim

If we convolve this image with a Gaussian kernel, we remove the high frequencies. The gausian "smooths" out the image. I used a 10 x 10 gaussian with sigma = 1.5.

A slightly blury cat lying in a toilet bowl

If we take the Fast Fourier Transform of the cat picture, we have the following (which was enhanced by raising all values to the 0.2 power):

The FFT of a cat lying in a toilet bowl

In this image, the low frequencies are all in the center. By default, MATLAB produces an FFT where the low frequencies are at the four corners. To select only the low frequencies, we can multiply the image by a mask which has solid white boxes in the corners and is black everywhere else. Because the boxes have hard edges which cut of frequencies at an exactly, the resulting image is not smooth.

A slightly blury and blocky cat lying in a toilet bowl

Interesting results can be produced if the location of low frequencies is switched in between the FFT and inverse FFT; the regenerated image is filled with a nice, swirling pattern. The cat also looks funny if you apply fftshift to the original image and display it, although this could also be acomplished with scissors and glue and involves no interesting processing.

Question 2

Sharpen an image using fspecial('unsharp') and imfilter.

This is straight forward. Just gennerate the unsharp filter and then use the MATLAB function apply the filter to the image. I used the default values for the unsharp filter. This is the original image:

A fish with a double rainbow.

And this is sharpened image. The difference is subtle, but noticable on the eyes and mouth.

A sharp fish with a double rainbow, which is possible starting to look like a triple rainbow

Question 3

Insert a ghost into an image

My goal was to add the ghost ontop of the base image to create a glowing effect. After trying unsucessfully to automatically extract a subject from a background with a mask, I decided to focus on the edges. I extracted the edges (the high frequency detail), by subtracting a blured (lowpassed) version of the image from the original. I then ran this through a median filter to remove some noise. Finally, I made a blured copy of the edge image. Adding the edges and the blurred edges to the original image gave the desired glowing effect.

The original pictures:

Dizzy Gillespie A beach scene at night

Picture by Libertinus

The composited image:

Dizzy Gillespie floating above a beach scene at night

Question 4

Reveal hidden secrets in a dark image.

The easiest way to reveal the detail in a dark image is to use the histeq function. This modifies an image so that its histogram is equally distributed over the entire dynamic range; there is no range of values where there are significantly more pixels than in other ranges. The original image:

A rocket takinging off in the night

The equalized image. We can see all the secrets.

A slightly blury cat lying in a toilet bowl