Wednesday, July 23, 2008
Activity 7: Enhancement in the Frequency Domain
Using the codes below, a 2D sinusoid was created and its Fourier Transform(FT) was shown.
nx = 100; ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
f = 4 //frequency
z = sin(2*%pi*f*X);
scf(1);
imshow(z,[]);
fftz = fft2(z);
scf(2);
imshow (abs(fftz), []); // FT modulus
The following images have frequencies of 2, 4 and 24. It can be observed that as the
frequency is increased the farther the points are from each other.
//Rotation
theta = 30;
z1 = sin(2*%pi*f*(Y*sin(theta) + X*cos(theta)));
fftz1 = fft2(z1);
scf(3);
imshow (abs(fftz1), []);
The following were rotated at 30, 45, and 60 degrees. The FT of the image is tilted just like
the original image is.
//combination
z2 = sin(2*%pi*4*X).*sin(2*%pi*4*Y);
fftz2 = fft2(z2);
scf(4);
imshow (abs(fftz2), []);
B. Ridge enhancement
Using the code below, the fingerprint was enhanced. This was done by using a high pass filter.
img = imread('C:\Users\nez\Desktop\activity 7 final\finger.jpg');
imgray = im2gray(img);
pic =imgray-mean(img);
scf(1);
imshow(pic);
im=fft2(pic);
ff=real((im).*conj(im));
scf(3);
imshow(fftshift(log(ff+1)),[]);
xset('colormap',jetcolormap(64));
//Transfer function
filter=mkfftfilter(pic,'exp',30);
scf(4);
imshow(filter);
//High-pass filter
IM=im.*fftshift(1-filter);
IMAGE=real(fft2(IM));
scf(5); imshow(IMAGE);
scf(6);
imshow(abs(fftshift(fft2(IMAGE))), []);
xset('colormap', jetcolormap(64));
(clockwise from top left: original image; mean centered image; FFT of mean centered image; FFT of enhanced image; enhance image; filter)
C. Line Removal
This was done using the code below. A filter was used to remove the lines from the original image.
img = imread("C:\Users\nez\Desktop\activity 7 final\hi_res_vertical_lg.gif");
imgray = im2gray(im);
Fimgray = fft2(imgray);
scf(1);
imshow(fftshift(abs(Fimgray)),[]);
//filtering
b = imread('C:\Users\nez\Desktop\activity 7 final\filter2.bmp');
a = imread('C:\Users\nez\Desktop\activity 7 final\hi_res_vertical_lg.gif');
bgray = im2gray(b);
agray = im2gray (a);
Fb = fftshift(bgray);
Fa = fft2 (agray);
FRA = Fb.*(Fa);
IRA = fft2 (FRA); //inverse FFT
FImage = abs(IRA);
imshow(FImage, [ ]);
Grade: 6/10 - It was passed late.
Monday, July 7, 2008
Activity 6: FOurier Transform of Image Model
circle
smaller circle Image above(clockwise from top left): original image; FFT of image; shifted FFT of image; original image with FFT applied twice.
I = imread('circle.bmp');
Igray = im2gray(I);
FIgray = fft2(Igray); //FIgray is complex
scf(1);
Image above(clockwise from top left): original image, FFT of image; image after applying FFT twice; shifted FFT of image.(The inverted image was scaled .)
*Simulation of an imaging device
a=imread('C:\MyDocuments\AP186\VIP.bmp');
rgray = im2gray(r);
agray = im2gray(a);
Fr = fftshift(rgray);//aperture is already in the Fourier Plane and need not be FFT'ed
Fa = fft2(agray);
FRA = Fr.*(Fa);
IRA = fft2(FRA); //inverse FFT
FImage = abs(IRA);
imshow(FImage, [ ]);
Using this code, the following images were produced:
Image above(clockwise from top left): original image; convolved image using circle image; convolved image using smaller_circle image; convolved image using smallest_circle image.
As we can see, as the circle being used gets smaller, the quality of the image becomes lesser.
*Template matching using correlation
r=imread('C:\MyDocuments\AP186\text.bmp');
a=imread('C:\MyDocuments\AP186\A.bmp');
rgray = im2gray(r);
agray = im2gray(a);
Fr = fftt2(rgray);
Fa = fft2(agray);
b = conj(Fr);
FRA = (Fa).*b;
IRA = fft2(FRA);
FImage= abs(IRA);
imshow(FImage, [ ]);
With this code, the originial image became unrecognizable. The texts in the image looked like letters A.
*Edge detection using convolution integral
pattern = [-1 -1 -1; 2 2 2; -1 -1 -1];
a=imread('C:\MyDocuments\AP186\VIP.bmp');
image = imcorrcoef(a, pattern);
imshow (image, []);
Using the code, the following images were formed. The first image shows a horizontal pattern since the pattern used here is also horizontal. The second image used a vertical pattern hence the image of VIP followed that pattern. It's also the same with the 3rd image, this time a spot pattern was used.
Acknowledgements: Jorge Presto
Grade: 10/10 - because the activity was well done.
Wednesday, July 2, 2008
Activity 5
//Generate 1-D sinusoid of form sin(2*pif*t)
N = 256;//number of samples
dt = T/N;//sampling interval
t = [0:dt:(N-1)*dt];
f = 5;//frequency
y = sin(2*%pi*f*t);
f1 = scf(1); plot(t,y);
FY = fft(y);
F = 1/(2*dt);//max frequency
df = 2*F/256;//discrete frequency
f = [-(df*(N/2)):df:df*(N/2 -1)];
f2 = scf(2);
Answers to questions:
4. In the case of images, 2-D Discrete Fourier Transform(DFT) will be used and is given by the formula:
Applying DFT will decompose the image to its sinusoidal components. Note that the Image should be in grayscale.
5.
a) The threshold sampling interval can be found by using the formula:
Fmax = 1/(2*dT)
where Fmax is equal to 120 Hz and dT is the threshold sampling interval.
This results to a thresholding sampling interval equal to 0.0041667
b) Increasing the number of samples N results to a higher peak as shown below.
N = 512; T = 4
c) Decreasing sampling interval dt results to a smaller interval between the peaks.
N = 256; T = 1
d) Increasing the number of samples N while fixing the total time interval T results to a higher peak but interval between them is the same with the original.
N =512; T = 2
Acknowledgement: Jorge Presto
Grade: 10/10 - Activity was done and questions were all answered.