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:
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.
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):
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.
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.
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:
And this is sharpened image. The difference is subtle, but noticable on the eyes and mouth.
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:
The composited image:
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:
The equalized image. We can see all the secrets.