Monday, July 7, 2008

Activity 6: Fourier Transform model of Image Formation

For this activity we performed fourier transform on images using the FFT2 function of scilab. For the first part we obtained the FFT of circles. The following image shows the FFT of a small circle.The leftmost image is the original image. The second to the left is the fourier transform (FT) of the original image, it can be seen that it is not consistent with the analytical FT of a circle. Shifting all the zero frequencies in the image produces the 3rd image, which is now consistent with the analytical FT of a circle which airy disks. The last image is the FT of the FT of the original image, it can be seen that the image returns to original which proves that FT is reversible. I also performed FT on a larger circle shown below.

It can be seen here that FFT becomes smaller as the image becomes larger, which is consistent with the theoretical expectations. FT was also performed in the letter A shown below:The important result for this part is that it confirms property 4 of the lecture. Which states that "The inverse FFT is just the same as the forward FFT with the image inverted"


For part B of the activity we obtained the convolution of 2 images. One image serves as the "aperture" and the other serves as the "object." Taking the convolution of this two objects is similar to obtaining the "image" of the "object" using the "aperture" as a "lens." The following results are obtained for a small aperture
For a small aperture, fewer frequencies pass through. Hence we observe a bad reconstruction of the original image.


For a larger aperture, the results show that we are able to reconstruct a better image. However, we are still not able to obtain perfect reconstruction as seen in the image because the color of the image is not similar to the original.

For part C of the activity, we are to obtain the correlation of the a letter in a long sentence. We are to find the correlation of the letter "A" in the phrase "THE RAIN IN SPAIN STAYS MAINLY IN THE PLAIN." I used Arial font size 16, boldface for this part, the following is the code that I used:
-------------------------------------------------------
S = imread("C:\Documents and Settings\Semicon.POSITRON\Desktop\activity6\6C\sentence3.bmp");
A = imread("C:\Documents and Settings\Semicon.POSITRON\Desktop\activity6\6C\A3.bmp");
grayS = im2gray(S);
grayA = im2gray(A);
fftS = fft2(grayS);
fftA = fft2(grayA);
mul = fftA.*conj(fftS);
inve = fft2(mul);
scf(1);imshow(grayS);
scf(2);imshow(fftshift(abs((inve))),[]);
-------------------------------------------------------
I obtained the following result for the same sized A,

In this image we can see that the parts of the sentence where the letter "A" appears is somewhat highlighted. This is because high correlation is obtained for the parts where the letter A is present. I also tried to find the correlation of the same letter but with smaller font size, I obtained the following result:
Here we see that the phrase is more clear however, parts where the letter A appears is not highlighted.

For the last part of the activity, we performed edge detection on the word VIP using different patterns. I used the patterns suggested by Dr. Soriano, which are horizontal, vertical diagonal and spot.

The following code was used to implement the image detection using scilab:
-------------------------------------------------------------------
VIP = imread("C:\Documents and Settings\Semicon.POSITRON\Desktop\activity6\6d\T.bmp");
VIP = im2gray(VIP);
pattern1 = [-1 -1 -1;2 2 2; -1 -1 -1];
pattern2 = [-1 2 -1; -1 2 -1; -1 2 -1];
pattern3 = [2 -1 -1; -1 2 -1; -1 -1 2];
pattern4 = [-1 -1 -1; -1 8 -1; -1 -1 -1];

corre1 = imcorrcoef(VIP,pattern1);
corre2 = imcorrcoef(VIP,pattern2);
corre3 = imcorrcoef(VIP,pattern3);
corre4 = imcorrcoef(VIP,pattern4);

imwrite(corre1,"C:\Documents and Settings\Semicon.POSITRON\Desktop\activity6\6d\hori.bmp");
imwrite(corre2,"C:\Documents and Settings\Semicon.POSITRON\Desktop\activity6\6d\vert.bmp");
imwrite(corre3,"C:\Documents and Settings\Semicon.POSITRON\Desktop\activity6\6d\diag.bmp");
imwrite(corre4,"C:\Documents and Settings\Semicon.POSITRON\Desktop\activity6\6d\spot.bmp");

scf(0);imshow(corre1, []);
scf(1);imshow(corre2, []);
scf(2);imshow(corre3, []);
scf(3);imshow(corre4, []);
-----------------------------------------------------------------------
The following results were obtained for "VIP":

The arrangement is original, horizontal, vertical, diagonal and spot. For the horizontal, most of the vertical components are missing, for the vertical, the horizontal components are missing, for the diagonal some components from the vertical and horizontal are missing while for the spot most components are present. I tried using the algorithm in the letter "T" which highlighted the results further specially for the diagonal since, T almost has no diagonal components.

Obviously, components corresponding to the diagonal is almost absent and horizontal and vertical components for their corresponding filters are clear.

I will give myself a grade of 10 because I believe I was able to do all the required task and also I was able to completely explain the results.


Abraham Latimer Camba Helped me in this activity

1 comment:

Jing said...

I liked that you did try out an experiment which was not part of the activity - the part where you tried what to see what happens if you reduce the font size of A. For this you deserve an 11.