Showing posts with label convolution. Show all posts
Showing posts with label convolution. Show all posts

Monday, July 13, 2009

A7 Enhancement In The Frequency Domain

Convolution is the smearing of one function against another so that the output looks a little like both. Mathematically it can be written as

In Fourier space, however, the convolution becomes a multiplication. That is the FT of a convolution of two functions in space is the product of the two functions’ FTs.

FT [ f g ]=FG

This is called the convolution theorem. It is this property of the convolution that makes it very convenient to do image enhancements and suppressions in the Fourier domain. We can just create a filter mask to remove or enhance some frequencies, multiply it to the image’s FT and do the inverse transform.

In this activity we first demonstrate some examples of convolution then use the theorem to enhance images.


A7A. Convolution Theorem


An image of a dot that is one pixel thick can be used to represent a dirac delta.We get the FT of two dots (dirac deltas) symmetric about the and see that it is a sinusoid pattern.



From the formula above, we can solve that the convolution of a dirac delta and a function f(t) results in a replication of f(t) in the location of the dirac delta.

A convolution of the two dirac deltas, above and a circle would just result to two circles in the locations of the peaks. From the convolution theorem, it can be predicted that the FT of this would just be a product of an Airy disk and the sinusoid pattern.

As the circle’s radius is reduced, the Airy disk becomes smaller. This can be seen in the images below. The sinusoid pattern however remains unaffected.

We already know from previous activities that the FT of a square is a sync pattern. The FT of the convolution of a square and two dirac deltas would therefore be just a sinc pattern with sinusoid linings. Increasing the square size reduces the size of the sinc pattern. The sinusoid retains its frequency.



Next the squares are replaced by Gaussians of varying variance. The resulting FT is that of a Gaussian with sinusoid patterns. Like the circle and square pairs the FT pattern becomes smaller as the variance becomes bigger.



Lastly, the values of the Gaussian were inverted as imaged below. Checking its fft, I found out that the values were just the negative of that of the fft of the original Gaussian.



The program that I used for this part is as follows.

clc;

x = [-1:0.005:1];

[X,Y] = meshgrid(x);

/////dots

rad=0.25;

r1 = sqrt((X-0.5).^2 + Y.^2); r2 = sqrt((X+0.5).^2 + Y.^2);

dots = zeros(size(X,1), size(X,2));

dots(find (r1 <=rad )) = 1.0; dots(find (r2 <=rad )) = 1.0;

//one pixel dots

//dots(find(X==0.5 & Y==0))=1;dots(find(X==-0.5 & Y==0))=1;

//////squares

d=0.25;

square= zeros(size(X,1), size(X,2));

square(find(abs(X-0.5)<=d & abs(Y) <=d))=1.0;

square(find(abs(X+0.5)<=d & abs(Y) <=d))=1.0;

/////// gaussian

sigma=0.005;

r1=sqrt((X-0.5).^2 +Y.^2);r2=sqrt((X+0.5).^2 +Y.^2);

g1=exp((-(r1).^2)/sigma^2) ;g2=exp((-(r2).^2)/sigma^2);

gaussian = zeros(size(X,1), size(X,2));

gaussian= g1 + g2;

gaussian=gaussian/max(gaussian);

/////// invert gaussian

invgaussian=1-gaussian;

image=square;

scf(1);

subplot(1,2,1);

imshow(image,[]);

//scf(2);

subplot(1,2,2);

imshow(fftshift(abs(fft2(image))),[]);


A7B Fingerprint Ridge Enhancements

Below is an image of a fingerprint. Notice that some of the ridges are indistinct and that some parts are smudged.



Our task was to do filtering in the frequency domain such that the smudges are removed and the ridges are enhanced. The fft of the fingerprint is as shown below


I interpreted the higher frequency areas to be from the ridges while the rest are from the noise.

For my first set of filters, I thought of using the im2bw() command to threshold the fft image so that only the high frequency areas are imaged. The image below shows the mask, the masked fft and the enhanced fingerprint for 0.2, 0.3 and 0.4 threshholds. We can see that for 0.2 and 0.3 although the ridges are enhanced so are the smudges. Threshold 0.4 clears the smudges but some information are also erased.



Next I tried the contrast enhancement and the thresholding of GIMP to create the filters. The firrst two filters did enhance the ridges...



but my best result was


Lastly, taking an idea from the first part of activity A, I tried an inverted Gaussian filter.



A7C. Line Removal
The image of the lunar landing below has a series of vertical lines in it.


We know from our previous activities that these lines would correspond to the bright spots aligned horizontaly on the fft.

We therefore use the filter


The enhanced image is now free of lines.



A7D Removal Of Canvas Weave

Th
e painting image below has its canvas weave pattern showing through.
From previous activities, we know that the cross hatch pattern are just crisscrossing sines and will therefore show up in the fft as pairs of dots.
To filter out the dots, we use
The enhanced image is

We expect the filtered out pattern to look like the weave when it is inversed fft.
In this activity, I give myself a grade of ten because I was able to do all that is required.

Monday, July 6, 2009

A5 Fourier Transform Model Of Image Formation

This activity is a demonstration of the many uses of the Fourier Transform.

We did this part by part and here are my results.


5.A FAMILIARIZATION WITH DISCRETE FFT


The FFT of an image is a transformation into inverse space or spatial frequency.

The function is built into Scilab and here are our results when fft2 is applied to a circle and to the letter A.

Original Image




FFT and zoomed Shifted FFT


FFT of FFT


Original Image



FFT and zoomed Shifted FFT




FFT of FFT

The output of fft2 has the quadrants along the diagonals interchanged; therefore fftshift is needed to realign the quadrants back. As expected the fft of a circle resulted to an Airy disk. Applying fft2 twice just resulted to an inverted copy of the original image.


5.B SIMULATION OF AN IMAGING DEVICE


The convolution model predicts the image produced when an object is viewed using an imaging sytem. Convolution is the smearing of one function with another such that the resulting function looks a little like both. In Fourier space, the product of the FTs of the image and the imaging system will give us the FT of the resulting image.

To simulate, we used the word “VIP” for our image and a circle to represent the aperture of an imaging device.

Original Image




We then applied fft2 to the image and fftshift to the aperture since the aperture is already in Fourier plane). The results after convolving are shown below. It was observed that as the diameter of the aperture gets bigger, the image becomes sharper. This is because a larger circle results to a smaller Airy disk.


Apertures



Resulting Images


5.C TEMPLATE MATCHING USING CORRELATION


Correlation measures the degree of similarity between two functions. The correlation value peaks at points where there is an exact match.


For example to find the letter A in the text…




…we use the template



We then element per element multiplied the fft of the template and the conjugate of the fft of the text. The image of the inverse fft is



The text is now inverted but we can still check that the bright peaks occur at the locations of the letter A.



5.D EDGE DETECTION USING THE CONVOLUTION INTEGRAL


Another application would be edge detection. We can convolve an image with a matrix pattern of an edge using the function imcorrcoef in Scilab.


When the edge pattern is horizontal the horizontal edges are emphasized.



Likewise for a vertical edge pattern.



Spot pattern gives me the best result


I give myself a grade of 10 because I was able to do all that was required in this activity.