Wednesday, July 8, 2009

Activity 6: Properties of the 2D Fourier Transform


Objective: To increase familiarity with the various

Tools: Scilab with SIP toolbox.

Procedure:

1. Familiarization of FT of Different 2D Patterns.

Using the same routines as with the previous activity, we take the FTs of the following apertures:
This yields the following FT patterns:


The first two patterns are identical to the ones from the previous activity. The third image is from an annulus and if we compute the far-field diffraction pattern(which is the same as the FT) we see that the result is a difference between two orders of Bessel functions. Hence we see a set of missing orders or fringes. The fourth is essentially the same only now the functions are sinc functions in x and y. The fourth is the double slit pattern at far field. This can be thought of as coherent oscillators interfering with each other. This means that the upper and lower sections cancel each others contribution. This leaves the central strip hence we only see a pattern at the center of the strip. The last image represents two circular apertures, this results in a modulation of the phase from the other hole causing the interfernce fringes that are superposed on the circular diffraction fringes.

2. Anamorphic Property of the Fourier Transform

A. We take a 2-D Sinusoid with frequency f=4:


We then take the FT of this pattern which yields two points in the transform plane. This corresponds to the frequency of the input. We do this for two other frequencies,f=1 and f=15 to get the following images arranged in increasing f:


We see that as the frequency increases, the points move further from the center. This makes sense if we treat the points as the frequncies of the sine waves (which they are). Thus as the frequency is increased the points move away from the center.

Now if we add a constant bias, we essentially add a field with all the possible frequencies present. Hence from Fourier theory, the FT of this is a single point. We see this when we get the mesh() of the biased sine wave. For comparison, we place on the left a mesh plot of the FT of the same wave without a bias:

The spike at the center represents the frequency of the bias or what is known as the zero-order component. Note that this is of a greater intesity than the sine spikes. If in a real image this becomes an issue, it is possible to subtract the constant value from the input image. This would leave the two spikes represnting the sine. The position of the spikes corresponds directly to the frequency hence we can find the spatial frequency of the fringes in areal image. On the other hand, if the bias is not constantand is a low f sine, we can use the FTs and remove the lower frequency component. We can then take the inverse transform to leave us with the filtered sinusoidal wave.

If we rotate the sine waves like the ones below:

We get the following patterns, which are consistent with the previous result:


If we multiply two sines or any function with two frequencies, we get a superposition of the transforms of both. In this case we use a product of two sne functions:

Which has a transform like:



This corresponds with what we expected as we see two sets of spikes which individually look like the pattern for a simple sine function.

For the last part, if wee add this function to the rotated sines above, we get an image which looks like:

Which has a transform like:



All this essentially tells us that the 2D FT obeys the priciple of superposition.

Reference: AP 186 Activity 6 Manual

Evaluation: For the proper results, a grade of 10 is warranted.

Monday, July 6, 2009

Activity 5: Fourier Transform Model of Image Formation

Objective: To introduce the use of the Fourier Transform or FT as the standard model for imaging applications highlighting the varied uses of this method for image processing.

Tools:
Scilab with SIP toolbox.

Procedure:The activity is divided into 5 parts each with its own focus.

1. Familiarization with the discrete FFT:
This section focuses on the use of the FFT as the mathematical equivalent of a lens. For this section we use two shapes, a circle and a square as our object and essentially image it with a lens of infinite aperture via the 2-D FFT function:


The corresponding FTs for these are as follows:



These image on the left represents the Airy disk of a point like image and the left image represnts the sinc(x)*sinc(y) function from a square aperture. This is how the patterns will appear on the transform plane on the back focal plane of a lens. Incidentally, these two images represent the far field or Fraunhofer diffraction pattern of the two aperture illuminated by a plane wave. When the FT of these images are taken we get the FT of the FT which are just the original images. On the other hand, if we use as our image a capital letter "A" as we have below:

We get a Fourier transform like the one we have below:
This indicates a center of symmetry even if the original image is only laterally symmetric. We also note that this patten may be thought of as a superposition of many point spread functions interfering with each other thus yielding this complex pattern. If we now take the FT of this image, we get an inverted "A" which can be thought of as the image of the object as seen through a lens system:

2. Convolution-Simulation of an Imaging Device.

The Convolution theorem essentially states that when the transform of two functions are multiplied it is equal to the transform of the product of the original functions. When this is translated into imaging, the image of an object ban be thought of as the convolution of the aperture function and the transfer function of the lens (or any other imaging system). In this case we use the the capital letters "VIP" in white against a blackbackground and a series of circular apertures simulating the aperture stop of the imaging lens. We take the FT of the aperture as imaged by a lens and then multiply it with the aperture which is in the transfrom plane. we then take the FT one more time to simulate another imaging lens.


We use the following apertures with increasing size.




















The corresponding imaged convolutions are:





















These correspond well to the fact that a larger aperture will produce a clearer image compared to a smaller aperture. At small apertures, the diffraction from the aperture actually limits the resolution of the imaging system.

3. Correlation-Template Matching
The section on correlation utilizes an image with certain text and a template letter. The correlatio is maximum when the section of the image matches completely with the template. This results in a large spot or spread function at the location of the match. In this case, we use the image on the left and then a template for the letter "A." The correlation is displayed on the right of these two:










The bright points indicate the regions of maximum correlation and these correspond clearly with the locations of the letter A in the image on the left.


4. Edge detection using convolution integral

In this last section we use the same concept as template matching to find the edges of an image pattern. This time we use matrices as our teplate instead of imges. Again we use the VIP image and find its edges using the following matrices:

A= -1 -1 -1
2 2 2
-1 -1 -1

B= -1 2 -1
-1 2 -1
-1 2 -1

and

C= -1 -1 -1
-1 8 -1
-1 -1 -1

With the following results:












Reference: AP 186 Activity 5 Manual

Evaluation: For the sheer amount of work expended as well as the proper results a grade of
10 is warranted.

Acknowledgements: I would like to thank the usual people for their assistance.

Sunday, July 5, 2009

Activity 4:Enhancement by Histogram Manipulation





Objective: To manipulate images via their corresponding histogram and to enhance images by altering the gray levels as indicated by the histograms.

Tools: Scilab with SIP toolbox.

Procedure: The first order of business is to convert a colored image into grayscale or find a low contrast grayscale image. In this case we use an image of the M17 Nebula taken by the Hubble Space Telescope from the site:
http://www1.cs.columbia.edu/~johnc/ta_page/6998s07/
schedule/proj1/proj1.html

We then take the histogram of this, as in the previous activity, by finding and counting the number of pixels which have a specific grayscale value and plotting these against the actual values. This yields a histogram like this:

We then take another function related to the histogram
called the CDF. This is essentially the cumulative sum
of the histogrm at each grayscale value. This is found simply by using the cumsum() function in Scilab. The CDF of the image above looks like:



In order to enhance the image the idealized CDF for thi
s is a straight, increasing line. Thus after generating such a f
unction, we use projection to replace the grayscale values in the original image with the grayscale values of the y-axis equivalents. This effectively replaces the grayscale values which cause the CDF to deviate from the ideal. The net effect, at least in theory is an increase in the contrast between light and dark regions. However as shown by the new, enhanced image below, the contrast does not change too drastically.
But if we look at the histogram and the CDF of this new image, we see that the new CDF is already ideal:
Additionally, we present other examples of images enhanced using respectively:


Monday, June 22, 2009

Activity 3:Image types and basic image enhancement


Objective: Differentiate image formats and apply basic image processing and conversion.

Tools: Image processing software and Scilab

Procedure: We use several different images:



1. RGBImage of NGC 2392, Eskimo Nebula
Taken from www.hubblesite.org200 x 200 pixels.
72x72 dpi
4kB in RGB











2. GrayscaleImage of M17 Nebula taken by HST
Taken from: http://www1.cs.columbia.edu
/~johnc/ta_page/
6998s07/schedule/proj1/proj1.html
200 x200 pixels
149.987 x149.987 dpi







3. Indexed
Colorized image of the entire sky at
gamma-ray energies
477x297 pixels
96 x 96 dpi
46.2 kB



Then in order to apply basic image processing techniques, we use a colored image and convert it to binary using a histogram routine to find the appropriate threshold value. Then we use the routine from the previous Activity to find the are of the ROI. Specifically, we use the figure shown below (taken from E. Marolda, The U.S. Navy in the Vietnam War)


This is then converted to binary using the im2bw routine which uses a threshold value to specify the gray level which is converted to either white or black. The following code is used to generate the historgram of the image:

clc
clf

img=imread('C:\Documents and Settings\2005-09860\Desktop\page3_2_en_sub.png');
//imshow(img);
a = 1;

g= [];
p= [];
for j = 1:256
[x, y] = find(img== j);
g(a) = j;
p(a) = length(x);
a = a + 1;
end
subplot(211)
//p=p/max(max(p));

plot(g,p)

-----------------------------------------------------------------------------------------------------
After conversion, the area of the image is taken using the routine in the previous activity. The routine indicates that this image has an are of 84500.5 units. Compared to the previous images processed, this appears to be a fairly accurate result.


Evaluation:For the effort expended and the acceptable result I can rate this as a 10.

Acknowledgements:I would like to thank Mr. Gubatan for insights on the histogram process as well as the usual folks for their assistance.

References: AP 186 Activity 3 Manual


Activity 2:Area estimation for images with defined edges

Objective: Use image processing software and Green's Theorem to compute the area of a regular polygon and compare this with the analytically computed area.

Tools: Scilab specifically the Image Processing Toolbox, MS Paint

Procedure: We use four different regular shapes drawn in black and white using MS paint.
These have areas of 10285, 6545, 5676 and 42121 square units respectively. Using the "follow" command in Scilab, we can get the x and y coordinates of the contour forming the border of the black and white regions. This creates two arrays of numbers called X and Y.

We then use a "for" loop to substitute these values of X and Y into the equation:where x and y are the coordinate arrays and the index i is the length of the array. This code is implemeted as follows:
______________________________________________________________
clc
clf

fig=imread('C:\Documents and Settings\2005-09860\Desktop\circ.bmp');
fig=im2bw(fig,0.5);
imshow(fig);

[x,y]=follow(fig);

i=length(x);
a=[];

for j=1:i-1
a(j)=x(j)*(y(j+1))-y(j)*x(j+1);
end

Area=sum(a)/2

______________________________________________________________

This code outputs a number which corresponds to the are of the polygon.

Results:


The following results were obtained using the shapes above:


These results correspond closely with the computed values. With the exception of the triangle, the deviations were all below 5% which indicates consistency. The triangle area may have a larger difference due to the manner in which a diagonal line is drawn in MSPaint. The line is drawn as a series of steps instead of a straight line.

Acknowledgements: I would like to thank the usual people for their help.

Refernces:
AP 186 Activity 2 Manual.

Rating: For this Activity, the acceptable correlation of the results with the actual values allow for a rating of 10.

Wednesday, June 17, 2009

Activity 1: Digital Sacnning

Objective: Use ratio and proportion to find the numerical values of a hand-drawn (or machine printed) plot.

Tools: MS Paint, Spreadsheet, image processing software

Description of procedure: We start with an scanned image of an old plot from some journal.


Figure 1. Original image of the plot.

We then take a fixed interval in an axis of the plot (which corresponds to a physical value) and note the number of pixels comprising this interval in the image. This give us a ratio of the physical quantity per pixel. For example, if the plot shows 100 units in the x axis and consists of 200 pixels in the image, we get a ratio of:


100 units/ 200 pixel= 0.5 units per pixel

We do this for both a and y axes. We then take the coordinates of the points in the plot and copy these into a spreadsheet. Using the ratios we derived earlier, we can then get the values corresponding to the physical quantities for both x and y axes. When these are plotted and the graph axes are adjusted to reflect the scale on the image, we get a plot that should correspond to the original drawing as we see below.



Figure 2. Overlay of origial plot and the plotted points from spreadsheet.


Comments: The results correspond well to the curve on the image. Note that the plotted points are represented as squares on the plot above. The main difficulty encountered is the scaling and the correlation of the axes which turns out to be a bit trickier than anticipated.

Source: Wood and Petrie, "Nitrogen metabolism of plants," Annals of Botany, Vol 2. 1938.

Acknowledgements: I would like to thank Doctors Soriano and Perez for their instruction. Also I would like to thank Misters Cabello, Dilla, Garcia, Gubatan and Villoan for their invaluable assistance.

Evaluation: For this activity I give mysely a grade of ten (10) for my output is quite acceptable and that the procedure for this exercise was thoroughly understood.

Additional Image: Trendline from spreadsheet showing logarithmic fit (compare with original scanned line)


Followers