Thursday, June 20, 2013

Activity 3 - Scilab Basics

The activity aims to apply basic knowledge on scilab to create synthetic images for testing algorithms or simulating optical phenomena in imaging systems.

Using the code in the handouts given by Mam Jing, we are able to construct a circular aperture of desired radius. The code with some of my comments, and the figure are as follows.

Scilab code:

//This part describes the grid to be manipulated on the next part.

nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates



//This part describes the synthetic image to be constructed

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; //desired radius is 0.3
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

Figure 1. Circular aperture generated by the given code


Next, is my turn to create synthetic images. This is in order according to the handouts. Also, the same grid from the first code is used for all the following images. I just changed the description part of the code.

a) Centered square aperture

Figure 2. Centered square aperture generated by the following code

// Centered Square
A = zeros(nx,ny);
r= (abs(X+Y) + abs(X-Y));
A (find(r<0.5) ) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

It took me sometime to understand how the basic operation were done on the grid because I am not yet so familiar with scilab. Thanks to my seatmate Shua, I was able to understand how it was applied.

b) Sinusoid along the x direction (corrugated roof)
Figure 3. Corrugated roof generated by a sinusoid along x

//Sinusoid
A = zeros(nx,ny);
r = sin(X*10);
A (find(Y>r) ) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

I guess I didnt have much problem in this part. I just searched images on the web describing a corrugated roof.

c) Grating along x axis
Figure 4. Horizontal Grating
Figure 5. Vertical Grating
//Grating
r = sin(%pi*Y.*10); // I used Y for Figure for and X for Figure 5.
A = zeros (nx,ny);
A (find(r > 0.1)) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

The only problem is that i don't know what exactly does "grating along x axis" means. I searched the web for images, and it showed a lot of Figure 4, but majority of my classmates(who i ask) tell me its Figure 5.


d) Annulus

Figure 6. Annulus image

//Annulus
r = sqrt(X.^2 + Y.^2);
A = zeros(nx,ny);
A (find(r>0.3 & r<0.6)) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

In these part i discovered the boolean functions for scilab specifically the AND function denoted by the symbol &.

e) Circular aperture with graded transparency
Figure 7. Circular aperture with graded transparency


r = sqrt(X.^2 +Y.^2);
A = zeros(nx,ny);
g = exp(-2*r.^2); //gaussian function
A(find(r<0.5)) = 1;
B = g.*A; //element by element multiplication
f = scf();
grayplot(x,y,B);
f.color_map = graycolormap(32);

The circled part was easy to create, but the inner part took me a lot of time, Until i realize that i can create a gradient image using the gaussian function, and a circle aperture separately, and i just need to superimposed them. I did it using the element by element multiplication. Since the circle aperture consists of 0 outside, which will always be 0 for any given factor, and 1 inside. Multiplying the circle aperture image to the gaussian function will result to Figure 7 above.

Exploration


Figure 8. Subtraction of the X and Y values

 A = X-Y
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Figure 8. Addition of the X and Y values
 A = X+Y
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Figure 8. Division of the X and Y values

A = X/Y
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

Figure 8. Multiplication of the X and Y values

A = X*Y
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

Figure 8.Multiplication of X^2 and Y values

A = X*Y*X
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);


I think i produced all required outputs as well as the exploration part, and my images are good quality and with proper labels.

Self-evaluation grade : 10/10

I guess i cant give myself a bonus point since the exploration i did was only limited to what the manual said, which is applying basic operations on matrix and observing the formed images. Unlike my classmates which also explored 3D imaging.

Acknowledgements

Thanks to Shua, and ate Bastine for answering my questions about scilab and other things.

Monday, June 10, 2013

Activity 2: Digital Scanning

The activity aims to replicate a hand-drawn plot using numerical values from digitally scanning it. The following figure shows the scanned hand-drawn plot provided for me by Justine Carpio. Also, according to her, the plot came from an undergrad thesis entitled Characterization of a UV pre-ionized TEA CO2 laser, by Marlon Rosendo H. Daza, dated September 1989.

Figure1. Scanned hand-drawn plot 

I opened this image using Paint; then from here I obtained numerical values of pixel coordinates for a range of tick marks in the plot.

Table 1. Tabulated data of tick marks with their corresponding pixel coordinate.

Using the built in function in Excel that shows the equation of the line for a graph, i obtained an equation relating the axes and the tick marks values for both x and y.

Figure 2. Graph of values from table 1 with the corresponding linear equation/relation for x axis
y = 0.0031x - 1.2031


Figure 3. Graph of values from table 1 with the corresponding linear equation/relation for y axis
y = -0.0009x + 2.7061

Now that we have the relation of the axis tick marks to the pixel coordinates. The next step is to sample the plot for its pixel coordinates, and use the equation to obtain the correct ratio of the plot. The following shows the tabulated results for the sampling of pixel coordinates of the plot, as well as its conversion using the two equations above.

Table 2. Sampling of pixel coordinates of the plot with their corresponding conversions.


I sampled this many, which is around 40 points, so that the plot can can also replicate the exact curves of the original plot.

Without further editing, the plot of the converted values of x and y can be shown by the following figure

Figure 4. Excel plot of the converted values of x and y from Table 2.

Visually, we can already say that the plot is almost the same as the scanned hand-drawn plot. To further observe the correctness of this method, we superimpose Figure 4. to a cropped image of the plot. Note that the axes are also superimposed. 


Now surely, we can say that produced output by using the method of digital scanning is an effective way of reproducing plots or images as well as reproducing values. As for the activity, i can rate the reproduced plot 10/10 for it really matched well with the original plot.

Accordingly, using the self evaluation guide, I think i deserve to have a grade of 5 for technical correctness as i was able to understood the lesson completely as well as produce all required output on time. And another 5 for quality of presentation given that all my graphs and images are properly labeled, captioned and of good quality. Also, from the handout itself, it says that being able to superimpose the original and the output would give you 1 bonus point. 

Thus, a total of 11 points.

I would like to thank Ate Bastine for giving me a scanned plot and especially for helping me create my  very FIRST blogsite , :)) Again, Thanks!