Scilab Basics

For the second activity in Applied Physics 186, we are asked to familiarize ourselves with programming with Scilab. Scilab is a much more user-friendly programming language with almost the same capability as that of Matlab.  In this activity, we are asked to plot 5 synthetic images namely; centered square aperture, sinusoid along the x-direction(corrugated roof),grating along the x-direction, annulus, and
circular aperture with graded transparency (gaussian transparency).  My codes are listed below;

//circle
nx=100;ny=100;
//x=linspace(-1,1,nx);
//y=linspace(-1,1,ny);
//[X,Y]=ndgrid(x,y);
//r=sqrt(X.^2 + Y.^2);
//A =zeros(nx,ny);
//A (find(r<0.7))=1;
//imshow(A,[]);
//imwrite(A,’Circle.jpg’);

//square
//x=linspace(-1,1,nx);
//y=linspace(-1,1,ny);
//[X,Y] = ndgrid(x,y);
//z=100;
//C=zeros(nx,ny);
//C(nx/2-z:ny/2+z,ny/2-z:ny/2+z)=1;
//imshow(C,[]);
//imwrite(C,’Square.jpg’);

//sinusoid
//x = linspace(-10,10,nx);
//y = linspace(-10,10,ny);
//[X,Y] = ndgrid(x,y);
//f = 7*%pi;
//E = sin(X.*f);
//imshow(E, []);
//imwrite(E,’Sinusoid.jpg’);

//grating
//x=linspace(-20,20,nx);
//y=linspace(-20,20,ny);
//[X,Y]=ndgrid(x,y);
//Y=sin(X);
//D = zeros(nx,ny);
//D(find(Y<0.10))=1;
//imshow(D,[]);
//imwrite(D,’Grating.jpg’);

//annulus
//x = linspace(-1,1,nx);
//y = linspace(-1,1,ny);
//[X,Y] = ndgrid(x,y);
//r=sqrt(X.^2 + Y.^2);
//B=zeros(nx,ny);
//B(find(r<0.7))=1;
//B(find(r<0.4))=0;
//imshow(B,[]);
//imwrite(B,’Annulus.jpg’);

//circular aperture with graded transparency
//x = linspace(-1,1,nx);
//y = linspace(-1,1,ny);
//[X,Y] = ndgrid(x,y);
//R=sqrt(X.^2+Y.^2);
//F = exp(-3*R);
//imshow(F,[]);
//imwrite(F,’Circular Aperture with graded transparency.jpg’);

To run the code the double slash should be removed for each corresponding plot.

The plots are shown in the following figures;

Figure 1. Practice Image - Centered Circle

The centered circular plot is the given example for this activity.  he radius of the aperture is 0.7.  However to obtain a more resolved graph, the number of elements can be varied.

Figure 2. Practice Image - Centered Square Aperture

This second figure is a more challenging image to plot.  It was actually the second to the hardest (next to the Gaussian Transparency).  The formula is more complicated as shown in the code for the square graph.

Figure 3. Practice Image - Sinusoid Along the x- direction (Corrugated Roof)

This is the plot of a corrugated roof using the sine function.  The formula used was sin(X.*f), where f is the frequency which defines the number of corrugation in the plot.  For this plot it was set to 7pi.

Figure 4. Practice Image - Grating Along x-direction

This plot is somewhat similar to the previous plot, I also used sine function to produce the gratings.  I just used the formula Y= sin(X) , however, for this, the mechanism for changing the number of gratings is different.

Figure 5. Practice Image - Annulus

The image above is an annulus.  The algorithm is a lot similar to centered circuar aperture but another aperture was added in zeros to block the portion of the bigger circle.  The radii used are 0.7 and 0.3  The fatness of the doughnut will be determined by the difference of the assigned radii.

Figure 6. Practice Image - Circular Aperture With Graded Transparency (Gaussian Transparency).

The last image is definitely the hardest to plot.  An exponential function was used for this.  It took me a long time to decipher what to do, with the help of some classmates.

All in all, this is an enjoying activity to do, especially if the Scilab easily worked with the SIP toolbox on the first time of trial.  It is rather frustrating to be stocked at some poit.  I rate myself 9 for this activity, since I think some of my codes are wrong although they produce the desired graph.  I would thank Millicent Singson, Celestino Borja, and Kaye Ann de las Alas for their valuable assistane to this activity.

Digital Scanning


The main objective of the activity is to enable the reconstruction of hand-drawn plots using conventional and simple programs.  For this activity, I was able to find an “ancient” hand-drawn plot from a journal compilation at the CS Library, Physical Review (Jan.-Jun. 1922).  The plot is concerned with the frequency characteristics of thermophones (although I don’t know anything about it).  It was scanned in grayscale and was cropped in Paint.  The plot (Figure 2) was then exported to GIMP where the pixel location analyses were done.  I don’t know whether it was fortunate or not to have 2 plots in the graph (although it was stated in the manual to be sure to have one plot in the graph).  However for complete and more sophisticated reconstruction, I decided to do both plots. Also, I did it to demonstrate that some plots are easier to reconstruct than the others and to somehow get a hint on the limitation of the technique.  Shown in Figure 1 is my reconstruction of the hand-drawn plots.

(A)

(B)

Figure 2. (A)   The original hand-drawn plot; (B) cropped image

To be able to visualize the accuracy of the reconstruction, the original plot was then superimposed as a background (Figure 3).

Now let me justify how I arrived with this reconstruction.  In the program, GIMP, the measure command let the user have information regarding the pixel location, with the origin at the upper left hand corner of the image (Paint, also, has this capability).  I just chose to use GIMP to make use of the color picker command for me to be sure that the point I am pointing to is colored black. With this, I was able to obtain 76 data points for the red plot (the lower one labeled A on the original plot), and 12 for the green plot (the upper one labeled B).  It is obvious that the latter is easier to interpolate (in the reconstruction) since it has a more common trendline, however, the former is a bit harder that’s why I decided to obtain plenty data points.  The data was tabulated in Microsoft Excel.  The pixel location was then related to the physical x-y quantities.  Using ratio and proportion, I was able to deduce multipliers to the pixel location.  For the x-coordinate, every 500 units on the plot have 50 pixels, so I multiplied 10 to the pixels I obtained.  On the other hand, for the y-coordinate, every 2 units have 50 pixels. Giving consideration to the fact that the y-coordinates of the pixel locations on the plot has a reversed order, and the supposed point 0 corresponded to 750, I first subtracted the pixel locations from 750 and then multiplied it with 0.04 (calculated from the ratio).  The obtained values were then plotted in Excel.

I can say that my reconstruction is somewhere between 95-98% accurate having doubt on the accuracy of the red plot because it has non-uniform curves.The plot is not that smooth since I have used many data points but I think doing it this way would make it more accurate.  Some observations, however, were observed while doing the activity.  Of course, simpler plots mean simpler reconstructions, and complicated ones also need complicated reconstructions.  The technique can be most efffective to plots with obeyed trendlines and can be least effective or even no use to complicated plots such as spectra and those noisy graphs (although, of course they are not hand drawn but if reconstruction is needed, this technique can be difficult to use).

All in all, this technique is effective in reconstructing hand-drawn plots (given that those hand-drawn plots were a lot simpler than those computer-generated ones).  In relation to my research in physics which involved spectroscopy, I have not yet found the application of the reconstruction but I realized one very essential technique which can be of big use to me.  While locating pixels, I realized that the technique in GIMP can be more effective and accurate (although, more tedious) to use in finding peaks in a spectra compared to the conventional spectrum analyzer program or manual peak locating in Excel.

I rate myself 9 for this activity, 5 for technical correctness and 4 for quality of presentation having an estimate of 95-98% accuracy of my plot.  I would like to acknowledge Millicent Singson and Xylene Azurin for useful advices while doing the activity.

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!