2. Scilab Basics

Scilab makes matrix multiplications very simple. The syntax is very much like the math. With matrices, synthetic images can be generated. A matrix of 1’s and 0’s form a black and white image (any binary set of values would do). Using more than two values will generate gray-scaled images.
In this activity, basic images were generated from Scilab matrices. I started from the code provided in class. This generates a circular aperture. I changed the number of elements (100 to 200) to improve the resolution of the image. The range was also increased to generate a larger image. This can be used as a mask for a matrix simulation of a light source.

All of the images generated are derived from this code.

nx = 200; ny = 200;
x = linspace(-2,2,nx);
y = linspace(-2,2,ny);
[X,Y] = ndgrid(x,y);
r= sqrt(X.^2 + Y.^2);
A = zeros (nx,ny);
A (find(r<0.7) =1;
annular aperture

A small modification of the code will generate a square aperture and an annulus. The white areas represented by 1’s. Changing lines [5], [6] and [7] to the following will yield the square and annular apertures.

To generate a square aperture
change [5],[6],[7] to

A(find(abs(Y)<1>0.5)) = 1;

To generate an annulus

A(find(r<1>0.5)) = 1;
square aperture
circular aperture
One can use the circular aperture with a simulated light source. Assuming that the beam’s distribution is Gaussian, we simply multiply the matrix of the aperture and that of the Gaussian source.

we simply add the following lines of code, omitting [8]

G = exp(-2*X.^2 - 2*Y.^2); //gaussian fxnB = G.*A;

Gaussian beam
Beam with circular aperture

Gratings can also be made by modifying the square aperture. Vertical gratings were made with the following conditions,

A(find(abs(Y)>n & abs(Y)n+.80 & abs(Y)n+1.60 & abs(Y)<2))>
Vertical gratings generated by imposing conditions on A along the x-axis

Trying out a sinusoid along the x-axis will generate this image.

Image of a sinusoid along the x-axis

This is generated by changing the conditions of the square aperture

A= sin(X*10);// apply sine function
A = A/max(A); //normalization
imshow(abs (A), []); //avoid negative values

For this exercise, I give myself a score of 9/10. The objectives of the activity are all in here. Minus one point for being late.

Thanks to Theiszm for the Scilab tips. Throughout the duration of the past week I have been (1) attempting to link SIP and then SIVP to Scilab 5 and (2) install SIP and SIVP from binary files to on my Linux. The binary installation took me into the trail of OpenCV and Cmake, very foreign installation requirements for me. I then gave up and took on Ma’am Jing’s advise to use Scilab 4.1.2 and SIP. The linking trick sure works. For the later versions of Scilab, the problem seems to be that it can’t find the file libsip.dll. I hope the SIP and SIVP link will workout in the later versions.


1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s