Monday, July 13, 2009

A7 – Enhancement in the Frequency Domain

Filtering in Fourier Space
"Unwanted repetitive patterns in an image can be removed by masking their
frequencies in the Fourier domain. Alternatively, desired frequencies in the image
may also be enhanced."

A Convolution Theorem


Figure 1.Results for steps 1 to 3.


Figure 2. Variance


As you vary the variance the FT intensity changes in such a way that increasing the variance increase the radius of the FT.


Fig 3. Inversion

To invert the gaussian dots such that highest becomes 0, lowest becomes 255
or 1.0 , I just multiplied the original values by -1 *255 and then added 255.

B. Fingerprints : Ridge Enhancement


Fig 4. The problem
After converting the image to grayscale, I took the FFT and from here try to create a mask to remove the frequencies of the blotches which is ... unknown.
So what I did is start by removing the higher frequencies...obviously using a circular aperture didnt work as seen in Fig.5.

Fig 5. Removing the higher frequencies with a circular aperture... didnt work

Next I tried the other way around, I didnt mask the higher frquencies but just retained it, then I tried cleaning the frequencies close the center as shown in Fig 6 until I finally tried creating a mask from the FT and just clean the FT as shown in Fig 7. The final almost cleaned finger print is shown in Fig 6 (last).

Figure 5.
Figure 6.

before(original fingerprint)
after-the enhanced fingerprint with ridges more clear and less blotches. This final image is from Figure 6c.

C. Lunar Landing Scanned Pictures : Line removal
Remove the vertical lines in the image by filtering in the Fourier Domain.
Fig 7. Lunar image with vertical lines


a. b.
Fig 8. a.FT and horizontal mask to remove the vertical lines. b. the FFT of thw masked FT, the final image is inverted with no more vertical lines.

Fig. 9. The final cleaned image after rotation.


D Canvas Weave Modeling and Removal


Fig. 10 The canvas with weave pattern

Fig 11. The graycale of canvas image



Figure 12.FT of the image




Fig 12. Tried a combination of gaussian filtering and masking the regions shown in c... didint work , the resulting image in e was too blurred.


Figure 13. Made a mask that removes the symmetric peaks around the center.

The mask in figure 13 b, removed the frequencies of the weave pattern and a cleaned image is retrieved by taking the FT again. Also, the cleaned image has higher contrast such that the brushstrokes are enhanced.
Fig. 14. The unwanted canvas weave pattern is now removed(im from Fig 13 c).



Fig. 14. The inverted mask of the peaks

Fig. 15. The FT of inverted mask. It does look like the canvas weave pattern.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Code:
a.Variance =2^2
b.Variance=3^2

nx = 100; ny = 100;

x = linspace(-100,1,nx);

y = linspace(-100,1,ny);

[X,Y] = ndgrid(x,y);

s1=4;//variance 1

s2=9;//variance 2

h=scf(1);

z1 = exp((-1*(sqrt((X+50).^2+(Y+50).^2)))/s1);

imshow(z1);

//xs2gif(1,'variance1.gif');

h=scf(2);

ft1=fftshift(abs(fft2(z1)));

imshow(ft1);

h=scf(3);

z2=exp((-1*(sqrt((X+50).^2+(Y+50).^2)))/s2);

imshow(z2);

//xs2gif(2,'variance2.gif');

h=scf(4);

ft2=fftshift(abs(fft2(z2)));

imshow(ft2);






Thursday, July 9, 2009

A6 – Properties of the 2D Fourier Transform

A .Familiarization with FT of different 2D patterns


Figure 1. a FFT of a circle, b. shifted FFT and c. FFT of FT resulting to the same circle.




Figure 2.
For Fig.2, the images above starting from the left are namely, an annulus, a square, square annulus, 2 slits and 2 dots all representing what we call apertures. The images on the bottom are their corresponding FT which is an Airy pattern for the annulus, a sinc function for the square apertures, double slit diffraction of maxima and minima in the horizontal axis for the vertical slits ans the sinusoid for the two dots.





a. b. c. d.
Figure 3. Comparison of a circular annulus and square annulus.

As expected the we have the a Airy pattern for a,b and a sinc function for c,d.
From these results we can say that the size of the aperture determines the intensity of the resulting diffraction pattern. It can be seen that the smaller the aperture is the brighter or more intense the FT or diffraction pattern is.



Figure 4. Variation in the dot size or pinhole radii

IT is shown in Fig.3 that the FT of 2 dots is a superposition of the FT of 2 small dots and FT of a circular aperture.



B Anamorphic property of the Fourier Transform

Anamorphic means something like producing different imaging effects along mutually perpendicular radii. We can see these in FT of perpendicular sinusoid signals.

Figure 5. Increase in the frquency

Increasing the frequency of the signal(sinusoid) resulted to the increase in the separation of the dots. We see here that the two dots corresponding to the frquency peaks shifted farther and father from the center, such that the lower the frequency the closer it is to the center while farther at higher frequency. The same with interferograms ,the spacing between the peaks of the FT of the signal gives corresponding frequency of the signal.


Fig.6 Effect of biasing


For a sinusoid of constant frequency and orientation, we expect that the peaks of the FT to remain the same since and it did and the position of the peaks did not vary. However the intensity of the dots was observe to change such that at low biasing the outer peaks were brighter and reduced at higher biasing which made (m=0) the central maximum peak brightest.


Fig.7

Since adding or subtracting the bias didn’t affect position of the peaks of the FT of the signal , we can just to choose to add the bias . For frequency=4, bias=0.1,1,10,100 was added to the sine wave and the resulting FT of the signal show that the only the intensity of the peaks varied and not the spacing.


Fig. 8


Rotating the signal(sinusoid) by an angle results to the rotation of the peaks of the FT.




Fig. 9

Top image shows the pattern and below is its Fourier transform .Now the combination of these sinusoids in X and Y with the formula

z = sin(2*%pi*4*X).*sin(2*%pi*4*Y);

has a FT that is again symmetric about the center and with peaks that correspond to the frequency of each sinusoid in their respective axis. The combined signal had the same frequency as illustrated in their perfect symmetry but once we changed one of the frequency of the signals, say in the X axis,

z4 = sin(2*%pi*8*X).*sin(2*%pi*4*Y);

the x separation in the vertical orientation increased. We recall that the higher the frequency the farther the peak from the center.

Fig 10

Addition of the combined sinusoids in the X and Y axis to 2 rotated sinusoids (theta=40,60deg) resulted to the image illustrated on top. Below is its FT which by inspection, is just the sum of the FT of each signal. The FT is thus useful for decomposing the frequency component in sampled signals.


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Monday, July 6, 2009

Activity 5 Fourier transformers!

-busy ang neurons...

Lens as Fourier Transformer

6.A – Familiarization with discrete FFT



Figure 1.



Figure 2.




Figure 3.



6.B Simulation of an imaging device


Figure 4.



Figure 5.


Figure 6.


6.C Template Matching using correlation

Figure 7.



Figure 8.


Figure 9.



Figure 10.



Figure 11.



6.D Edge detection using the convolution integral


Figure 12.

Monday, June 29, 2009

Activity 4 Enhancement by Histogram Manipulation

The histogram of a grayscale image is equal to the graylevel probability
distribution function (PDF) if normalized by the total number of pixels. As such,
the grayscale PDF of an image can be modified in the same way one can modify
the PDF of random numbers.
Histogram manipulation is one way of improving the quality of an image,
enhancing certain image features, or mimicking the response of different imaging
systems, such as the human eye.
Given the cumulative distribution function (CDF) of a desired PDF, the grayscale
PDF of an image can be modified by backprojecting the grayscale values using
the CDF. Then
newly encountered functions in scilab:
tabul - frequency of values of a matrix or vector
tabul allows
you to compute the frequency of of occurence of a vector or matrix
[m]=tabul(X [,order])
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Activity 4:
Two categories of image enhancement techniques include spatial and frequency domain techniques. Spatial techniques involve direct manipulation of image pixels while frequency domain techniques works by manipulation of fourier of the and wavelet transform of a signal.
Here, the spatial technique will used by way of histogram enhancement. The histogram of an image illustrate the distribution of gray levels in the image in the range 0 to 255 where 0 is black and 255 is white and normalized when in the range [0.0, 1.0].
The method of histogram enhancement works by equalization.This is one of the ways in which it can be done in Scilab:
You get the histogram of the image by using the tabul(filename, ‘i’) command that gives the frequency of occurrence of the matrix or vectors, or in this case the no. of pixels having that graylevel and then plot it.
The histogram:
x axis for the graylevel
y axis for the frequency value

Next, normalize the greylevel and you distribute the frequency over the total no. of pixels and thus spread out the most frequent intensity values.


Results and discussions:



Using linear method of histrogram equalization, we see in Fig.1 that the resulting new image has a well distributed histogram as compared to the original image which has uneven probability distribution. The new image has a higher contrast than the original.


In Figure 2, using nonlinear histogram equalization using interp1(,,'linear') was used. However the resulting image has lower contrast than the original.

For this image the linear method was able to enhance the contrast in the image while the non linear method was not and only resulted to reduction in grayvalue of each graylevel.


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Code:
linear

im=imread('C:\Users\USA\Desktop\scilab and 186\grayscale parrot.png');

m=tabul(im,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(321);

imshow(im,[]);

subplot(322);

plot(nx,ny);

title('PDF1- Histogram 1');xlabel('grayscale level');ylabel('frequency');

subplot(323);

plot(nx,ccy);

title('CDF1');

//2. backprojection of the image through the CDF original

newim= [];

for i = 1:px

for j = 1:py

newim(i,j) = ccy(im(i,j));

end

end

subplot(324);

imshow(newim,[]);

//scf(1);

//imshow(newim,[]);

//imwrite(good1, 'newim.jpg');

/////for this newimage get the PDF and CDF again

im=imread('C:\Users\USA\Desktop\scilab and 186\newim.jpg');

im=tabul(newim,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(325);

plot(nx,ny);

title('PDF2- Histogram of Image 2');xlabel('grayscale level');ylabel('frequency');

subplot(326);

plot(nx,ccy)

title('CDF of Image 2');

xs2sgif(0,’figure1.gif’);


code: non linear:


im=imread('C:\Users\USA\Desktop\scilab and 186\grayscale parrot.png');

m=tabul(im,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(321);

imshow(im,[]);

subplot(322);

plot(nx,ny);

title('PDF1- Histogram 1');xlabel('grayscale level');ylabel('frequency');

subplot(323);

plot(nx,ccy);

title('CDF1');

// for the equalization by backprojection of the image through a desired cdf

xx=[0:1:255];

yy=xx^2;

yy=yy/max(yy);

xxp=[];

yyp=[]

for i=1:px;

for j=1:py;

xxp(i, j)=ccy(im(i,j));

end

end

yyp=interp1(yy,xx, xxp,'linear');

//yyp=interp1(yy,xx, xxp,' spline');

//yyp=interp1(yy,xx, xxp,'nearest);

newim=yyp;

subplot(324);

imshow(newim, []);

newim=round(newim);

subplot(324);

imshow(newim,[]);


im=imread('C:\Users\USA\Desktop\scilab and 186\newim.jpg');

im=tabul(newim,'i');hx=m(:,1);hy=m(:,2);

scf(0);

[px,py]=size(im);

np=px*py;

nx=hx/max(hx);

ny=hy;

ccy=cumsum(ny)/max(cumsum(ny));

subplot(325);

plot(nx,ny);

title('PDF2- Histogram of Image 2');xlabel('grayscale level');ylabel('frequency');

subplot(326);

plot(nx,ccy)

title('CDF of Image 2');

xs2sgif(0,’figure1.gif’);