Tuesday, July 14, 2009

Activity 7 - Enhancement in the Frequency Domain

This activity is composed of 4 major parts which introduce us to image enhancement in the frequency domain via the Fourier transform.

Activity 7-A - Convolution Theorem
Different apertures are again created similar to the previous activities for the application of Fourier transform (FT). However this time, the convolution theorem is illustrated through the FT of some images.
Initially, a two-dot single pixel aperture symmetric about the horizontal axis is made in Paint. Its FT is shown below.



It can be observed that a periodic FT pattern is produced. This is expected since the FT of two dirac deltas along an axis symmetric to the center is a sine function with frequency corresponding to their separation.

Next, instead of dots, they are replaced with circles with varying radius.





For the apertures above, the convolution theorem comes in. the FT of a circular aperture which displays airy disks is then convoluted with the FT of dirac deltas which is a sine function similar to the two-dot single pixel aperture. Hence, we see airy disks pattern with vertical alternation of bright and dark stripes. As we increase the radius, airy disks become smaller but the vertical stripes are still discernable.

After circular apertures, they are substituted with squares. Their widths are also varied.




The FT of a single square aperture is a sinc function. This is then convoluted to the FT of the first aperture. Hence, we observe sinc pattern with vertical alternating bright and dark stripes. Like in the circular apertures, the FT image becomes smaller as the width increases.

Pairs of Gaussian apertures are used next. They are in the form



where sigma is the variance and mu is the location of its maximum. Variance is changed for different Gaussian aperture sizes.





It can be observed that as the variance of the Gaussian aperture is increased, the FT image which is a single Gaussian function centrally located gets smaller.

A Gaussian aperture is inverted as depicted as follows having the brighest to be the darkest and vice-versa.



Then, its FT is acquired without getting the modulus or absolute values. The real and imaginary part is comparable to the non-inverted Gaussian aperture such that they cancel out when multiplied. This inversion property in the Fourier or frequency space is exploited for the next sections of this activity.

Activity 7-B - Fingerprints: Ridge Enhancement
An image of a fingerprint is downloaded from the internet for this part of the activity. Then, this image is enhanced particularly emphasizing its ridges at the same time removing its blotches. The process is done in the frequency domain through designing a filter that can enhance the image. In a more detalied steps, the image is read in grayscale-type then its FT is then multiplied element-by-element to the shifted filter through fftshift in Scilab. Note that we are enhancing the image in the frequency domain that is, the filter created is already in this domain, thus it is no longer required to shift the image. Finally, the inverse FT is applied to the product and this corresponds to the enhanced fingerprint image.




Source: http://www.cs.tau.ac.il/~turkel/images.html

The upperleft image is the original fingerprint image downloaded from the website as written above. The next one is the FT image of the original image from which the filter below is based. It can be observed from the FT that there are regions where the intensity is higher than the others. These correspond to the frequency of the ridges thus they are made white in the filter for emphasis. Higher order frequencies which are attributed to blotches and other noise in the image are then blackened in the filter. As the enhanced fingerprint image shown above, the ridges are emphasized at the same time, although not totally removed, the blotches are very much diminished.

Activity 7-C - Lunar Landing Scanned Pictures: Line Removal
The third part of the activity has also the same procedure as the second, except that here, unnecessary patterns from the image are removed. From a scanned picture of lunar landing as the activity suggested to improve, there are vertical lines that are to be removed. Again, the filter used is based from the FT of the original image. The set of images below summarizes the results.




A horizontal line is drawn as the filter leaving the center in white. This is because the lowest orders of frequencies which correspond to the primary image information are found here. Recall from the first part that the Gaussian aperture is inverted such that the real and imaginary parts of its FT can cancel out the FT of the non-inverted aperture. So, in this case, since horizontal aperture has FT of vertical patterns, the filter is designed as illustrated above. Hence, the resulting enhanced lunar landing picture no longer contains the vertical lines and its primary image information still remain.

Activity 7-D - Canvas Weave Modeling and Removal
The last part is similar to the previous section except that a different pattern from the image must be eliminated. An oil painting from the Vargas Museum collection is to be enhanced by removing the canvas weave pattern on it. The following images are the results.




The FT of the grayscaled original image shows distinctive bright spots which correspond to the canvas weave pattern. Thus, they are blocked in the filter used for enhancement. Consequently, there are no longer weave pattern seen in the resulting oil painting image. However, the brushstrokes in the painting are not enhanced since they depend on the weave pattern.
In modeling a canvas weave pattern, the filter is inverted and modified to single-pixel bright spots. Its FT is then obtained. These are shown below.



Ideally, the canvas weave pattern is generated through the superimposition of sinusoidal waves in both horizontal and vertical propagation having different frequencies. Thus, the filter is simplified as composed of only single-pixel bright spots which are equivalent to dirac deltas, recalling that the FT of a pair of dirac deltas is a sine function.

So far, this is the longest activity I've successfully completed, but since I have accomplished all the requirements of each section and gained better understanding about image enhancement in the frequency domain, I grade myself 10/10.

Throughout the activity, I have collaborated with Gary and Raffy who have brought useful insights during our discussions.

Appendix
The whole Scilab code used in this activity is as follows.

stacksize(4e7);
I2dots = gray_imread('2dotpixels.bmp');

//scf(0);
//imshow(abs(fftshift(fft2(I2dots))), []);
//imwrite(abs(fftshift(fft2(I2dots)))/max(abs(fftshift(fft2(I2dots)))), 'F2dots.bmp');

//I2circles = gray_imread('2circleslargestradius.bmp');

//scf(1);
//imshow(abs(fftshift(fft2(I2circles))), []);
//imwrite(abs(fftshift(fft2(I2circles)))/max(abs(fftshift(fft2(I2circles)))), 'F2circleslargestradius.bmp');

I2squares = gray_imread('2squareslargerwidth.bmp');
2squares = abs(fftshift(fft2(I2squares)));

//scf(2);
//imshow(abs(fftshift(fft2(I2squares))), []);
//imwrite(abs(fftshift(fft2(I2squares)))/max(abs(fftshift(fft2(I2squares)))), 'F2squareslargerwidth.bmp');

a = 100;
b = 100;
m = 0.5;
s = 0.2;
x = linspace(-1, 1, a);
y = linspace(-1, 1, b);
[X, Y] = meshgrid(x, y);
g = exp(-((X + m).*(X + m))/s^2).*exp(-(Y.*Y)/s^2) + exp(-((X - m).*(X - m))/s^2).*exp(-(Y.*Y)/s^2);
//scf(3);
//imshow(g, []);
//imwrite(g/max(g), 'gaussianm0.5s0.2.bmp');

Igaussian = gray_imread('gaussianm0.5s0.2.bmp');
Fgaussian = abs(fftshift(fft2(Igaussian)));
Fgaussian2 = fftshift(fft2(Igaussian));
realFg = real(Fgaussian2);
imFg = imag(Fgaussian2);
//scf(4);
//imshow(Fgaussian, []);
//mesh(Fgaussian);
//imwrite(Fgaussian/max(Fgaussian), 'Fgaussianm0.5s0.05.bmp');

ginv = max(g) - g;
//scf(5);
//imshow(ginv, []);
//imwrite(ginv/max(ginv), 'gaussianinv.bmp');
Iginv = gray_imread('gaussianinv.bmp');
Fginv = fftshift(fft2(Iginv));
realFginv = real(Fginv);
imFginv = imag(Fginv);

moon = gray_imread('hi_res_vertical_lg.gif');
Fmoon = log(abs(fftshift(fft2(moon))));

//scf(6);
//imshow(Fmoon, []);
//imwrite(Fmoon/max(Fmoon), 'Fmoon.bmp');

filtermoon = gray_imread('filtermoon.bmp');
bettermoon = abs((ifft(fftshift(filtermoon).*fft2(moon))));
//scf(7);
//imshow(bettermoon, []);
//imwrite(bettermoon/max(bettermoon), 'bettermoon.bmp');

fingerprint = gray_imread('fingerprint.jpg');
Ffingerprint = log(abs(fftshift(fft2(fingerprint))));
//scf(8);
//imshow(Ffingerprint, []);
//imwrite(Ffingerprint/max(Ffingerprint), 'Ffingerprint.bmp');

filterfingerprint = gray_imread('filterfingerprint.bmp');
betterfingerprint = abs((ifft(fftshift(filterfingerprint).*fft2(fingerprint))));
//scf(9);
//imshow(betterfingerprint, []);
//imwrite(betterfingerprint/max(betterfingerprint), 'betterfingerprint.bmp');

canvas = gray_imread('canvasweave.jpg');
Fcanvas = log(abs(fftshift(fft2(canvas))));

//scf(10);
//imshow(Fcanvas, []);
//imwrite(Fcanvas/max(Fcanvas), 'Fcanvas.bmp');

filtercanvas = gray_imread('filtercanvas.bmp');
bettercanvas = abs((ifft(fftshift(filtercanvas).*fft2(canvas))));
//scf(11);
//imshow(bettercanvas, []);
//imwrite(bettercanvas/max(bettercanvas), 'bettercanvas.bmp');

filtercanvasinv = gray_imread('filtercanvasinv.bmp');
Ffiltercanvasinv = abs(fftshift(fft2(filtercanvasinv)));
//scf(12);
//imshow(Ffiltercanvasinv, []);
//imwrite(Ffiltercanvasinv/max(Ffiltercanvasinv), 'Ffiltercanvasinv.bmp');

No comments:

Post a Comment