top of page

Activity 3

Scilab Basics

Programming is the modern language of scientific computations. Almost all educational institutions have curricula on machine and computer language learning. These courses often include the more common and famous languages like C, C++, and Python. Most of these languages can suffice and are flexible enough for general purpose applications. However, some numerical calculations are much convenient to operate on “scientific languages” like MatLab. MATLAB is one the most used software in research involving optics and photonics. One reason is that MATLAB is optimised for element by element operations on matrices. But there is a catch. MATLAB is very expensive and technical support is often necessary if bugs are encountered.

Good thing there are advocates on fighting against digital imperialism and the monopoly of softwares. These advocates, volunteers, and enthusiasts, created SCILAB. Scilab is free and open source software for numerical computation providing a powerful computing environment for engineering and scientific applications [1].

For this activity, the goal is to create synthetic images such as optical apertures and waveforms using Scilab. The first thing that I did was to reconstruct a circular aperture. The snippet below shows the Scilab code on how it is done.

Basically, line 3 creates 1000 x and y points and the function linspace divides the range -1 to 1 to 1000 points. ndgrid function creates the 2-D array of x and y coordinates. Line 7 defines the equation of a circle entered at (0,0). The function find identifies if a pixel is within the specified radius which is 0.7 in our case. When the pixel is within that radius, it is colored light brown as shown in the first image below.

Synthetic Images Generation

Circular Aperture

The circular aperture is often the first type of aperture that is recreated in convetional scientific simulations of optical and imaging systems. The basic methodology of constructing this aperture is the stepping stone of much complicated aperture shapes.

Centered-Square Aperture

The next task is to generate other aperture shapes and waveforms. The first was a centered square aperture. To do this, just set a linear boundary condition for both X and Y arrays with the use of absolute value function in scilab. Follow this link for the codes [2].

Sinusoid Along x-direction

(Corrugated Roof)

Moving on to another aperture shape, is the sinusoid along the x-direction, also known as the corrugated roof (visually appropriate). To do this, the sine function in Scilab is invoked. It is expected that the darkest band should be at 1 while the lightest band should be at -1 of the horizontal axis of the plot.

Grating Along the x-direction

The next synthetic image is almost identical to the corrugated roof. The difference is that the boundaries are more defined and distinct. To do this in Scilab, the square wave function is used. This image is simply called “grating along the x-direction”.

Annulus

This image is one of my favourite. I always see this kind of aperture in Fourier Optics books. A true crowd favourite - the annulus. It can be done by adding minor revisions to the circular aperture code. By setting two threshold values for the radius, everything that is inside the bounds will be tagged as brown pixels.

Circular Aperture with Gradient

Transparency (Gaussian)

Another variation of the circular aperture is one with a graded transparency that follows a gaussian profile. To accomplish this, the circular aperture is just multiplied (element by element) to the Gaussian equation. The peak of the gaussian distribution is located at the its mean while the spread is given by the standard deviation.

Elliptical Aperture

Yet another variation of the circular aperture is the elliptical aperture. One just vary the coefficients of the circle equation. A bigger value for the Y coefficient would make the major axis of the ellipse prominent along the horizontal direction.

Cross Aperture

The last synthetic image is a cross aperture. This is done by varying the cenetered square aperture. But unlike the range in the square aperture, the lower range limit of both X and Y coordinates should not be zero. The width and length of this cross can be varied by changing the threshold values.

Exploring More Patterns

Copper Gradient

I got this plot by multiplying a sine function with an exponential function. It is apparent from the graph that the sinusoidal tendency is shaped by an exponential increase in intensity.

Eye Strain Test

 The image on the left was a result of element per element multiplication of two orthogonal corrugated roof. Two sine functions were used to form the blurry interwoven effect that looks like an eye strain test on optical clinics.

Table Cloth

This table cloth pattern is constructed from two orthogonal squarewave multiplied element per element. Unlike the eye strain test (based from sine functions), the boundaries of the table cloth are defined and distinct.

The Saddle

This image is a result of adding and subtracting sines and cosines, and then multipying them element per element:

A = Xcos(50pi) - Ysin(50pi)

B = Xsin(50pi) + Ycos(50pi)

Tilted Cross

The tilted cross can be done in two ways: rotating the cross aperture by a rotation matrix or translating the absolute value center of the square apperture. I have done te latter. The width of the cross can be altered by changing the threshold values of the translated absolute value centers.

Overall, the activity taught me a lot about the syntax of Scilab! I am now excited to try a lot of image processing using it as my main tool (aside from the mathematical jargons and algorithms). Overall, I rate my self 10/10 because I successfully recreated the required synthetic images. Oh right, I did 5 exploration images so I’ll make it 12/10. The activity was really fun. :)

References:

[1] Scilab. Retrieved from: http://www.scilab.org/scilab/about

[2] Barteezy's Applied Physics Experience. Retrived from: https://barteezy.wordpress.com/2015/08/22/activity-3-scilab-basics/

[3] M. Soriano, “Scilab Basics,” Applied Physics 186 Activity Hand-outs, 2014.

bottom of page