Thursday, July 10, 2008

Activity 7: Enhancement in the Frequency Domain

A. Anamorphic property of the Fourier Transform

nx = 100; ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);

f = 4

z = sin(2*%pi*f*X); imshow(z,[]);
//the FT is taken and it gives the following FT modulus image:Varying the frequency results in the peaks of the FT being farther apart (the white dots in the image) as seen by the following FT modulus images with the frequency of the sinusoid image 6 and 10, respectively. This is expected as the characteristic of the fftshift() moves the higher frequencies away from the middle of the image,in 2D F(0,0).//rotating the sinusoid:
theta = 30; z = sin(2*%pi*f*(Y*sin(theta) + X*cos(theta)));

at an angle theta also rotates the FT but at an angle of negative theta as seen by the image.

//combining sinusoids in the x and y, like the one called by the line:
z = sin(2*%pi*4*X).*sin(2*%pi*4*Y);produces an FT, the peaks of which are the peaks of the sine and cosine components, this results in its intensity image having the peaks(white dots) of the x-y/sine-cosine.B. Fingerprints : Ridge Enhancement

The original image from www.defensetech.org/archives/images/arch.jpg:using the following code:
stacksize(4e7);
I=imread('C:\Documents and Settings\Endura\My Documents\186\thumb3.jpg');
fig=fft2(I);
imshow(abs(fftshift(fig)),[]);

xset("colormap",hotcolormap(20))


//it reads the fingerprint image (which is already in grayscale) and returns a colored(using colormap) image of the fingerprint fft-ed and fftshift-ed.//using the function mkfftfilter to create a filter mask to enhance the image by "bringing out" the ridges and getting rid of the rest of the blurred parts. A high-pass filter is used since the ridges have higher frequencies, which can also be deduced from the above fft modulus image.
im2=fig-mean(fig);
h=mkfftfilter(im2,'exp',50);

img=fig.*fftshift(1-h);
im=real(fft2(img));

imshow(im);

**the filter has a radius of 50, but is use the high-pass filter lets through all frequencies that come outside of the circle with radius 50.resulting in the following "enhanced" image:
C. Lunar Landing Scanned Pictures : Line removal

original image//Using the same proces (and code) as the previous part, the vertical lines are removed from the above image.
**First a low-pass filter was used with radius (threshold frequency) 27
athough this does quite effectively remove the vertical lines from the image, it seems that the overall quality of the image is compromised, especially details of the surface.

**Then i used a band-pass filter to try and recover the higher frequency lines that should help give the picture more definition. This also uses the same process as the second part, except that the lines that call the filter are different.
h1=mkfftfilter(ig,'binary',100);
h2=mkfftfilter(ig,'binary',27);

h=h1-h2;

IM4=fig.*fftshift(1-h);

im4=real(fft2(IM4));
imshow(im4,[]);


With the upper threshold high, there is no observable difference between the result of using the low-pass and the band-pass filters:Lowering the upper threshold frequency though only either adds some surface noise to the image, or brings back the vertical lines that were meant to be erased in the first place. The problem is probably that the frequency of the vertical lines and that of the lines that better define the grooves of the surface are ,if not one and the same, are very very close, so that getting rid of one also gets rid of the other.


UPDATE: i found a better, more effective filter design for this activity but i'm having a hard time uploading pictures,will try and upload them again later.

UPDATE:
so last friday i looked at the fft of the lunar landing photo and noticed the pronounced horizontal line across the middle that crosses a relatively fainter vertical line, and realized that these represent the lines in the image.
so i set about making a filter with a black vertical line and horizontal line crossing at the very center and used this to process my image with the following program:
I=imread('space.jpg');
F=imread('act7cfft.jpg');
ig=im2gray(I);
fig=fft2(ig);

fts=fftshift(F);
im=fig.*fts;
ima=fftshift(im);

img=abs(fft2(ima));
imshow(img,[]);
...this, of course, FAILED and produced the following image.then jeric said that his filter was a simple horizontal line (since only the vertical lines in the image need to be deleted) with a gap in the middle (to retain some of the data). Using the same program above, i created a filter like his (using trial and error to get the width of the gap just right to get rid of lingering traces of the vertical lines).obtaining:
This image now has no visible traces of the vertical lines while retaining the quality/clarity discarded by a simple low/band-pass filter. I also tried adding a black vertical line with a (smaller) gap in the middle to this filter to see the effect.This produces the following image which looks relatively cleaner than the last one because the thick grey horizontal line in the middle is gone, as expected.


**i give myself a grade of 10 for this activity because I was able to comply with the objectives of the activity, produce the desired images, within the time allotted for the activity.

**thank you, as usual, to jeric for helping me with the colormap problem and the little program mishaps I usually always screw up when i start coding. Also, thank you to cole for the invaluable help with the mean-centered image and filter things.

No comments: