We start off by observing the properties of FT in repetitive images and other symmetric patterns.
Figure 1. (a) 2 Pixel dot symmetric along the x- axis (b) Fourier transform image
As we can see, the image with two small dots produced a sinusoid pattern on the FT space. We know, from previous activity, that an object symmetric about the x axis, can be considered as a convolution of the object and a two dots symmetric at the x axis, and thus with the convolution property, the FT of
The next part is the implementation of convolution
//Creating 200x200 image with 10 randomly placed ones
A = zeros(200,200);
for i = 1:10
A(round(rand(1)*200),round(rand(1)*200)) = 1;
end
imshow(A);
imwrite(A,'C:\Users\GreyFOX\Desktop\Activity 8\random.png');
d = imread('C:\Users\GreyFOX\Desktop\Activity 8\flower.png');
d1 = double(rgb2gray(d));
FTA = fft2(A);
FTd = fft2(d1);
FTAd = FTA .* FTd;
inverse = mat2gray(abs(fft2(FTAd)));
imshow(inverse);
imwrite(inverse,'C:\Users\GreyFOX\Desktop\Activity 8\convolvedflwr.png');
Basically, its the flowery pattern convolved to a randomly placed dirac delta, is the just the same as placing the flowery pattern randomly.
Lastly, using the results in the previous part, we may now began to study how the FFT enhances images.
Given an image
Figure 2. (Left) Two circles with increasing radius (from top to bottom); Right) Corresponding FT of the left image
Like from previous activity, increasing the size of the shapes decreases the airy function that the FT produces.
Using the following code, i implemented these for square and a gaussian symmetric along x-axis
nx = 500; ny = 250; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-0.5,0.5,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
//Two Circles
r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r<0.3) ) = 1;
B = zeros (nx,ny);
B (find(r<0.3) ) = 1;
C = [A B]; // CIRCLE
//Two Squares
S1 = zeros(nx,ny);
r= (abs(X+Y) + abs(X-Y));
S1 (find(r<0.1) ) = 1;
S2 = zeros(nx,ny);
S2 (find(r<0.1) ) = 1;
S = [S1 S2] // SQUARE
//Two Gaussian Circles
r = sqrt(X.^2 +Y.^2);
sigma = 0.01
g = exp((-2*r.^2)/sigma**2); //gaussian function
A = zeros(nx,ny);
A(find(r<0.1)) = 1;
B1 = g.*A;
B2 = g.*A;
G = [B1 B2] //GAUSSIAN
imshow(C); //Choose if Circle, Square, or Gaussian
imwrite(C,'C:\Users\GreyFOX\Desktop\Activity 8\r=0.3.png')
Cft = abs(fft2(C));
image = mat2gray(fftshift(Cft));
imshow(image);
imwrite(image,'C:\Users\GreyFOX\Desktop\Activity 8\r=0.3fft.png' );
Note that I used this code to create the desired initial image and its corresponding FT for Figure 2. and the following results. Notice the codes for square and gaussian images.
Square
Figure 3. (Left) Two squares with increasing length (from top to bottom) , (Right) Corresponding FT of the left image
Gaussian
Figure 4. (Left) Two gaussian circles with increasing sigma (from top to bottom, sigma = 0.05, sigma = 0.1, sigma = 0.3) (Right) Corresponding FT of the left image
The next part is the implementation of convolution
//Creating 200x200 image with 10 randomly placed ones
A = zeros(200,200);
for i = 1:10
A(round(rand(1)*200),round(rand(1)*200)) = 1;
end
imshow(A);
imwrite(A,'C:\Users\GreyFOX\Desktop\Activity 8\random.png');
d = imread('C:\Users\GreyFOX\Desktop\Activity 8\flower.png');
d1 = double(rgb2gray(d));
FTA = fft2(A);
FTd = fft2(d1);
FTAd = FTA .* FTd;
inverse = mat2gray(abs(fft2(FTAd)));
imshow(inverse);
imwrite(inverse,'C:\Users\GreyFOX\Desktop\Activity 8\convolvedflwr.png');
Figure 5. Result from Convolution of the two upper image
Lastly, using the results in the previous part, we may now began to study how the FFT enhances images.
Given an image
Figure 6 .Lunar Orbiter image of one of the craters in the far side of the moon with its corresponding FT.
From the previous part, we know that what we need to do is that to remove the thin line forming a cross through the center. More importantly, since the center possess all the information, we should take note to filter only the thin lines forming a cross as much as possible.
Figure 7. Thin lines used as mask to filter the thin lines.
The last thing to do is to retrieve the image after filtering out the thin lines. The line used as mask is 3 pixel in width, to make sure complete masking.
Figure 8. Retrieving the image after masking.
Finally, we obtained this image, which is obviously enhanced.
I will give myself a grade of 10, for producing the results from the most basic up to main objective of this activity. the which is to ENHANCED images using our knowledge about the Fourier Space.
No comments:
Post a Comment