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&lt;0.7) =1;

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)&lt;1&gt;0.5)) = 1;

To generate an annulus

A(find(r&lt;1&gt;0.5)) = 1;

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

G = exp(-2*X.^2 - 2*Y.^2); //gaussian fxnB = G.*A; imshow(G,[]); imshow(B,[]);

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

n=.20 A(find(abs(Y)>n & abs(Y)n+.80 & abs(Y)n+1.60 & abs(Y)<2))>

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

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