Scilab Basics
Scilab is an open-source programming language designed specifically for scientific computations. It has similar features and syntax with Matlab thus practical for the manipulation of matrices. By application of the basic operations in Scilab 4.1.2 and Signal and Image Processing (SIP) Toolbox, synthetic images can be easily created. As an example, consider the following image of a circular aperture.
To produce this, the following code should be executed in Scilab.
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, []);
Here, the space matrix A corresponds to the size of the whole image. When a certain element is assigned a value of 1, it will turn out white whereas that assigned a value of 0 will turn out black. These conditions were used to simulate the following synthetic images.
CENTERED SQUARE APERTURE
Here, the midpoints along x and y were obtained to determine the center of the image. Then a value of 1 was assigned to a range from the left and right of the center (in this case: 100) thus forming a square.
nx = 500; ny = 500;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
A = zeros (nx,ny);
A((nx/2) – 100: (nx/2) + 100, (ny/2) – 100: (ny/2) + 100) = 1;
imshow (A, []);
SINUSOID
To produce a sinusoid along the x-direction, the sine function is simply applied to the X values multiplied by a certain frequency.
nx = 100; ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
A = sin(20*X);
imshow (A, []);
GRATING
For a grating in the x-direction, the elements along x were divided into parts. Then a value of 1 was assigned to certain elements.
nx = 500; ny = 500;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
A = zeros (nx,ny);
A(1:(nx/10), 1:ny) = 1;
A((nx/10)*2:(nx/10)*3, 1:ny) = 1;
A((nx/10)*4:(nx/10)*5, 1:ny) = 1;
A((nx/10)*6:(nx/10)*7, 1:ny) = 1;
A((nx/10)*8: nx, 1:ny) = 1;
imshow (A, []);
ANNULUS
The code for this is basically the same as that of the circular aperture; only it has an additional condition for the values of the elements of matrix A. The innermost circle with radius less than 0.4 was assigned with a 0 value.
nx = 500; ny = 500;
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;
A (find(r<0.4)) = 0;
imshow (A, []);
CIRCULAR APERTURE WITH GAUSSIAN TRANSPARENCY
For this, a two dimensional Gaussian function was used.
nx = 500; ny = 500;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
G = exp(-5*X.^2 -5*Y.^2);
imshow (G, []);
Self evaluation: 10/10
P.S. I would like to thank Joseph Bunao for guiding me through this activity. 🙂





