Scilab is an open-source software which is effective for array and matrix operations [1,2]. Therefore, it is also an effective programming language for image processing like Matlab.
For this activity, we were tasked to install Scilab 5.3.3 from http://www.scilab.org and the Signal Image and Video Processing (SIVP) module from http://www.scilab.org/products/modules/scm. Primarily, Scilab was installed in our computers. To check whether it was successfully installed, a simple snippet was executed:
If this snippet works, then the next step was to install the SIVP module. For my case, the downloaded SIVP_0.5.3.1 folder was copied to C:\Program Files\scilab-5.3.3\contrib since my Operating System is 32-bit Windows 7 Starter. The Module Manager – ATOMS button in the standard toolbar was clicked followed by the SIVP_0.5.3.1 in the Toolboxes tab of the Scilab console.
To check whether SIVP works, the imshow command should be working. The algorithm which simulates a centered circular aperture or a centered circle in 2-dimensions was given. Once this algorithm displayed the corresponding image, then the SIVP module was properly installed. The Scilab code is shown below and the corresponding output image is shown in Figure 1.
//centered 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);
The next procedure is to simulate other algorithms which demonstrate optical phenomena in imaging. The first is a synthetic image of a centered square aperture. The Scilab code for this image was actually a modified version of the code for the centered circular aperture. At first, I was thinking of using for loop but when I heard from Ma’am Jing that Scilab is a good programming language because it can execute algorithms shorter than other language, the abs function came to my mind. From that time on, I thought of ways on how to optimize my codes. The code and the image for the square aperture is shown below. A line preceded by a double slash denotes a comment.
//centered square 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(abs(X)<0.3 & abs(Y)<0.3)) = 1;
imshow (A);
A synthetic image of a sinusoid along the x-direction was also simulated. It is shown in Figure 3.
The code for this image is shown below. Another way to display the sinusoid is by using the mesh plot shown in Figure 4. Its shape is similar to a corrugated or rippled roof. I chose sin(3*pi*X) because I want a bigger wavelength.
//sinusoid along the x-direction (corrugated roof)
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
A = zeros (nx,ny);
A = sin(3*%pi*X);
mesh (A); //if 3-dimensional
//imshow (A); //if 2-dimensional
I want to thank Rommel Bartolome for telling me that the mesh plot can be used in this item.
The third synthetic image which was asked to be simulated was a grating along the x-direction. I noticed that Figure 3 can look like a grating if there where no “gradient” in the values. That is why, I thought of modifying the sinusoid code then look for a threshold value and set it to 1 in order to make a grating. The code is shown below. My threshold for this case is 0.9.
//grating along the x-direction
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
A = zeros (nx,ny);
A(find(abs(sin(3*%pi*Y))>0.9)) = 1;
mesh (A); //if 3-dimensional
imshow (A); //if 2-dimensional
The corresponding grating image along the x-direction is shown in Figure 5.
Alternatively, the mesh plot can also be used to this kind of function but it will not show a grating. It will only show a series of ups and downs like that of a 2-bit synchronous counter.
The next image created was an annulus. In Mathematics, it is defined as the area between two concentric circles with different radius [3]. Since it talks about rings, I modified the centered circle Scilab code by choosing to values of radii. These will be the concentric circles and the area between them will be the annulus. The Scilab code is shown below. Moreover, the image of the annulus is shown in Figure 6.
//annulus
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.3 & r<0.7) ) = 1;
imshow (A);
The last task is to create an image of a circular aperture with graded transparency or Gaussian transparency. From the term itself, I thought of a transparent medium which has a Gaussian distribution, meaning the middle has the highest transmittance T and the value of T dies down in all directions since we were dealing with 2-dimensional matrices. It was not indicated if this aperture is center but for symmetry and convenience purposes, I chose to make the aperture centered.
In this case, I made use of Gaussian function. In 2 dimensions, this function centered at (0.5,0.5) is expressed as
where the 0.2 value is the width of the kernel [4]. The Scilab code is written below and Figure 7 shows the said image.
//circular aperture with graded transparency (Gaussian transparency)
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
A = zeros (nx,ny);
A = exp(-(X.^2 + Y.^2)/(2*0.3^2)); //note element-per-element squaring of X and Y
imshow (A);
Scilab was already introduced to us last semester in Applied Physics 185. I can still remember I had a very hard time installing the SIVP module. The good thing is that there were some computers in the computer room installed with Scilab. But now, it is successfully installed in my laptop and I can enjoy the free and convenient Scilab program language. This activity did not only focus on the basics of Scilab but also on basic matrix operations. I have learned that Scilab is a good programming language if we are dealing with matrices.
For this activity, I will give myself a grade of 10/10 because I was able to finish the codes before 1pm despite having the hard time to install Scilab and SIVP. I think my figures are also clear even if the resolutions were 100 x 100 pixels only. I followed the instructions in the manual. I cannot give myself some bonus points, I guess, because I did not make use uint8(). I did my codes based on how I can imagine the images in my mind.
References:
1. “Key Facts”, available at http://www.scilab.org/aboutus/consortium/key.
2. Maricor Soriano, “A2 – Scilab Basics”, Applied Physics 186 laboratory manual, 1st semester AY 2012-13.
3. “Annulus”, available at http://www.thefreedictionary.com/annulus.
4. “Plotting 2D Functions”, available at http://www.site.uottawa.ca/~edubois/courses/CEG4311/plotting_2D.pdf.