Thursday, June 13, 2013

A3 - Scilab Basics


This activity capitalizes on Scilab's relative ease in operating with matrices.

Using the code :

nx = 100; ny = 100; //defines the number ofelements 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 xand y coordinates
r= sqrt(X.^2 + Y.^2); //note element-per-elementsquaring of X and Y
A = zeros (nx,ny);
A (find(r<0.7) ) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

given by Ma'm Jing to create a circular aperture we were tasked to study it and use it to create 
different images. 

                               
                                                            Fig 1. Centered circular aperture

The first image that was easiest to recreate was the annulus which is like two 
concentric circles centered at the middle. I merely gave the region, with radii between 0.4 and 0.7,  in    the range [-1,1] in both axes, a value of 1 using the code shown below.

nx = 100; ny = 100; //defines the number ofelements 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 xand y coordinates
r= sqrt(X.^2 + Y.^2); //note element-per-elementsquaring of X and Y
A = zeros (nx,ny);
A (find(r<0.7 &  r >0.4) ) = 1;// portion between circles of radii 0.4 and 0.7 is given a value of 1
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
this results in the image shown below. 
Fig 2. Annulus with black center
Another annulus can be created by switching the values of A making the default value 1 instead of an array of 0's using the below code,
nx = 100 ; ny =1 00; //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
r= sqrt(X.^2 + Y.^2)//note element-per-elementsquaring of X and Y
A = ones (nx,ny);// made 1
A (find(r< 0.7 & r >0.4)) = 0;// portion between circles of radii 0.4 and 0.7 is gibven a value of 0
f = scf ();
grayplot(x,y,A);
f.color_map = graycolormap(32);

This gives an aperture with a white center as shown below. 
                                    
    Fig 3. Annulus with white center
The next image that was easiest to create is the square centered at the middle. Using the code shown below where I defined the side of the square to be r with a length of 0.4 I was able to accurately derive such a square.

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 xand y coordinates
r= 0.4; // side of the square
A = zeros (nx,ny);
A (find (abs(X)<r & abs (Y)<r))=1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

                                                Fig 4. White square aperture centered in the middle



The corrugated roof or the sinusoid along the x axis was the next image I created. I used the 
da = gda() default function and x_label.text  to label the x  in order to show that the sinusoid is indeed oriented along the x-axis. I also made the x-axis range from -1 to 2.


nx = 100 ; ny =100; //defines the number of elements along x and y
x = linspace(-1,2,nx);//defines the range. Note that x ranges from -1 to 2 and y ranges from -1 to 1
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);//creates two 2-D arrays of x and y coordinates
da=gda()
da.x_label.text="x";// label for x axis
A = sin(X.*%pi*7); f = scf (); grayplot(x,y,A); f.color_map = graycolormap(32);

The image is shown here, 
                                         Fig 5. Sinusoid along the x-axis forming a corrugated roof
The next image I created was the circular aperture with graded transparency (gaussian transparency). Using the definition of the Gaussian

nx = 100; ny = 100; //defines the number ofelements 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 xand y coordinates
r= sqrt(X.^2 + Y.^2); //note element-per-elementsquaring of X and Y
A = zeros (nx,ny);
A = (exp(-r) ) ;// using definition of Guassian 
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
                                                 Fig 6.  Gaussian transparent circular aperture
The last image I was able to create was the grating along the x-axis. I used the for loop to set all 
columns of A which are multiples of 10 to have a value of 1 yielding 10 gratings for the 100 elements in the x axis. 

nx = 100; ny = 100; //defines the number ofelements along x and y
x = linspace(-1,2,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of xand y coordinates
da=gda()
da.x_label.text="x";// label for x axis

; // for x and y axes labels
A = zeros (nx,ny);
for r = 1:10:nx
    A(:,r)= 1
    end

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

This gave me the image with 10 gray gratings across the x-axis. I used the x.label.text 
to properly identify the x from the y axis. I also made the range of x from -1 to 2 to differentiate it from
 the y axis.  This is seen in the image below 
                                                                      Fig 6. Gratings across the x-axis

Honestly, I think I deserve a perfect 10/10 because  I did everything that was asked and I properly labelled all pictures ( they can stand alone) and adequately explained my rationale. 



Tuesday, June 11, 2013

A2 - Digital Scanning



                                   A2 - Digital Scanning


    We were tasked to recreate digitally scanned hand-drawn graphs. I used Image J to locate the pixel locations on the graph and Microsoft Excel to tabulate their coordinates. 

The original scanned image , generously donated by my classmate Justine Carpio is shown below


                        
                       Fig 1. Original image of hand-drawn graph digitally scanned and provided by Ms. Justine Carpio

     The hand-drawn graph describes the relationship between the spectral radiance L vs the wavelength of  blackbody sources at various temperatures. I chose to recreate the  plot corresponding to the blackbody source at 1895 K.  I cropped the graph from the above photo creating a new image file with dimensions 1036 x 1324. This is shown below

                                             
                              Fig 2. Cropped image of hand-drawn graph with dimensions 1036 x 1324 pixels

       I then used Image J to find the pixel locations of the tick marks in the x and y axes. The y-axis is in the logarithmic scale so tabulating the results for the pixel locations of the tick marks in  y-axis and its corresponding magnitude ( in log) I got the table below. The magnitudes are the physical variables which in this case are wavelength and spectral radiance.



     

y ticks pixels
Magnitude
1169
7
1008
8
849
9
691
10
531
11
371
12
211
13
54
14

  Table 1. Pixel location and magnitude of the physical variable ( Spectral Radiance) of the tick marks in the y-axis


Graphing it  and setting the linear trend line, I got the equation relating the pixel location a tick mark on the y-axis with its corresponding magnitude. This equation can then be used to find the magnitude on the y-axis of any point on the graph with a known y pixel location

                           
 Figure 3. Graph of Table 1 with the corresponding equation for the linear trend line giving the relationship between pixel location and radiance 

I repeated this with the tick marks on the x-axis and its magnitudes giving me the table 

x ticks pixels
Magnitude
175
0
334
1
491
2
650
3
812
4
974
5
 Table 2. Pixel location and magnitude of the physical variable ( Wavelength) of the tick marks in the x-axis

and its graph 

Figure 4. Graph of Table 2. with the corresponding equation for the linear trend line giving the relationship between pixel location wavelength


with the equation for the linear trend line, y=.0063x -1.0867 , which I used to find the x-magnitudes of points with known x pixel locations. 

   I tabulated the a and y pixel locations of 17 points on the curve corresponding to the 1895 K blackbody source  shown in the cropped image with dimensions 1036 x 1324 and applied the equations y=-.0063x + 14.332 to find the x-magnitudes and y=.0063x -1.0867 to find the y magnitudes which I tabulated. The process of using ratio and proportion is exercised by Microsoft Excel in the derivation of the trend line equation. I came up with the table shown below 

test x
test y
test x mag
test y mag
229
1170
0.356
6.961
235
1090
0.3938
7.465
243
1010
0.4442
7.969
251
927
0.4946
8.4919
259
850
0.545
8.977
270
768
0.6143
9.4936
287
690
0.7214
9.985
312
618
0.8789
10.4386
341
564
1.0616
10.7788
424
530
1.5845
10.993
494
546
2.0255
10.8922
576
566
2.5421
10.7662
657
596
3.0524
10.5772
735
624
3.5438
10.4008
818
650
4.0667
10.237
890
670
4.5203
10.111
980
688
5.0873
9.9976

 Table 3.  x and y pixel locations of 17 points chosen on the curve corresponding to the blackbody source as 1895 K and its computed magnitudes using the equations shown in Table 1 and 2.

where the columns text x and text y correspond to the pixel locations of the 17 chosen points and the columns test x mag and text y mag correspond to the magnitudes of these points in the x and y -axes. I graphed these magnitudes and made the background image of the plot a cropped image showing the curve of the blackbody source at 1895 K. The plot of the graph using the values from the table above almost matches the actual one as shown in the figure below. 



Figure 5. Final Output. Graph of the computed x and y magnitudes shown in Table 3 which is an attempted recreation of the plot shown in Figure 2 ( specifically the curve corresponding to the blackbody source at 1895 K). the recreated curve matched the actual curve. 

      Using the rubrik given in the 186 syllabus I believe I deserve a 10 in this activity because my images, text and tables are of excellent quality with captions that can definitely stand alone. My only flaw was that my recreated plot doesn't  perfectly match the original. My output however shows that I understood the lesson completely enough. Maybe I deserve 9.5 at worst but if we're rounding up then I think I get a should get a 10 :D yay.