Activity 2: Scilab Basics
Basically this activity aims to familiarize us with some capabilities of Scilab and it's SIP toolbox. The goal of this activity is to create synthetic images for:
- centered square aperture
- sinusoid along the x-direction (corrugated roof)
- grating along the x-direction
- annulus
- circular aperture with graded transparency (gaussian transparency)
chdir(ImageMagickPath);from http://www.scilab.org/contrib/index_contrib.php?page=displayContribution&fileID=146
link('CORE_RL_magick_.dll');
and reloading the toolbox but it still won't work.
Following Dr. Soriano's example code for make a circular aperture:
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
r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r < 0.7) ) = 1;
imshow (A, []);
I get:

Now it's my turn to do...
- centered square aperture:
- sinusoid along the x-direction (corrugated roof):
- grating along the x-direction:
- annulus: (from here onwards I used 256 by 256 pixels)
- circular aperture with graded transparency (gaussian transparency):
The code for all these is:
nx = 256; ny = 256; //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
Pinhole
r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r < 0.7)) = 1;
Centered Square Aperture
A = ones (nx,ny);
A(find(abs(X) > 0.4)) = 0;
A(find(abs(Y) > 0.4)) = 0;
Sinusoid along the x-direction (corrugated roof)
A = ones (nx,ny);
x = 2 * 2 * %pi * linspace(-1, 1, nx);
[X,Y] = ndgrid(x,y);
A = sin(X)
minimum = min(A)
A = (A - minimum)
maximum = max(A)
A = A/maximum
Grating along the x-direction
A = ones (nx,ny);
A(find(abs(X) < 1.1)) = 0;
A(find(abs(X) < 0.9)) = 1;
A(find(abs(X) < 0.7)) = 0;
A(find(abs(X) < 0.5)) = 1;
A(find(abs(X) < 0.3)) = 0;
A(find(abs(X) < 0.1)) = 1;
Annulus
r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r < 0.7) ) = 1;
A (find(r < 0.3) ) = 0;
Circular aperture with graded transparency (gaussian transparency)
r= sqrt(X.^2 + Y.^2);
A = exp(-r.^2/0.15)
A(find(r > 0.6)) = 0;
Cross
A = zeros (nx,ny);
A(find(abs(X) < 0.15)) = 1;
A(find(abs(Y) < 0.15)) =1;
Double slit along y
A = zeros (nx,ny);
A(find(abs(Y)<0.25)) = 1;
A(find(abs(Y)<0.15)) = 0;
Half moon
r= sqrt(X.^2 + Y.^2);
A = zeros (nx,ny);
A(find(r < 0.6)) = 1;
A(find(Y > 0)) = 0;
Smiley
r= sqrt(X.^2 + Y.^2);
A = zeros (nx,ny);
A(find(r < 0.5)) =1;
A(find(X < 0)) = 0;
A(find(((X+0.4).^2 + (Y+0.4).^2) < 0.01)) = 1;
A(find(((X+0.4).^2 + (Y-0.4).^2) < 0.01)) = 1;
imshow (A, []);
imwrite(A, 'pinhole.jpg');
imwrite(A, 'centered_square_aperture.jpg');
imwrite(A, 'annulus.jpg');
imwrite(A, 'sinusoid x.jpg');
imwrite(A, 'grating x.jpg');
imwrite(A, 'circ graded transparency.jpg');
imwrite(A, 'cross.jpg');
imwrite(A, "double slit.jpg");
imwrite(A, 'half moon.jpg');
imwrite(A, 'smiley.jpg');
Just comment out segments of the code to produce specific patterns. Grading myself, I would give it a score of perfect 10/10 for being able to produce all the required patterns, for understanding the lesson and presenting the images with proper labels. Plus, a bonus of two points for going beyond the requirements and trying it out with other patterns.
Score: 12/10
Lastly, I want to thank Dr. Soriano, Bayosa Aya Carino and Aivin Solatorio for giving insights and helping me with this activity.
- Dennis Diaz
No comments:
Post a Comment