So
our activity for today was to get familiar with the programming language that
is Scilab. The objective was to create synthetic images out of test
algorithms.
Centered Square Aperture
Code
Snippet in Scienotes:
nx = 100; ny = 100; //defines
the 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 2D arrays with x and y coordinatesnx = 100;
l = abs(X); //length
w = abs(Y); //width
A = zeros (nx,ny);
A (find(l<0.5 & w<0.5) ) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
As one can see I could
have made a rectangle just by simply editing the length and width. It can be
edited on lines 5 and 6.
Sinusoid along the
x-direction (corrugated roof)
nx = 100; ny = 100; //defines
the 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 2D arrays with x and y coordinatesnx = 100;
A = zeros(nx,ny);
A = 10*sin(20*X); //defines
the sinusoid with frequency and amplitude
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
This was achieved by simply letting the matrix (A) have the assigned values of sine with varying frequency on line 6 of the code snippet. The frequency is 20 while the amplitude is 10.
Grating along the
x-direction
nx = 100; ny = 100; //defines the 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 2D arrays with x and y coordinatesnx = 100;
A = zeros (nx,ny);
g = 10*sin(20*X);
A (find(g<0)) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Annulus
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-element squaring of X and Y
A = zeros (nx,ny);
A (find(r<0.7 & r>0.3) )= 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Circular Aperture with graded transparency (Gaussian transparency)
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
Z = exp(-X.^2 -Y.^2);
f = scf();
grayplot(x,y,Z);
f.color_map = graycolormap(32);
Here is a product of the Sine function and Gaussian function.
Here is a product of the Sine function and Gaussian function.
Code Snippet:
nx = 100; ny = 100; //defines the 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 2D arrays with x and y coordinatesnx = 100;
G = sin(10*X)*exp(-X.^2 - Y.^2);
f = scf();
plot3d(x,y,G);
f.color_map = graycolormap(32);
Pretty cool huh?
No comments:
Post a Comment