All of us living creatures are always peeking at things through a hole all of the time. Not the one you’re thinking perv! What I meant is through an aperture, like the one in our eyes, in our cameras.

Right now, I’m not gonna talk about apertures and lenses and cameras and all of that. Rather, let’s make some apertures instead using SciLab!

SciLab is a free programming software that is very similar in functionality to MathLab but cheap. As in FREE kind of cheap.

So why SciLab? The reason behind this is because (1) it just handles matrices easily and (2) we were required to. HAHAHA. So without spending too much time on the intro, let’s dive right in!

For this activity, we need:

  1. SciLab (of course). Get the whole package here.
  2. that’s pretty much it.


STEP 1:  Learning some Basics

<Disclaimer> For all the pros out there, just skip this part. Hell, please skip this whole post. This is really for noobs — like me. 

For the purpose of this post, we’re just keeping the basic tutorial limited to matrix manipulation in SciLab. Other basics like syntax and functions can easily be Googled. </Disclaimer>

As we knew from the previous post, image points are located within some Cartesian coordinate system in pixels. We can address each of these points using matrices but before I delve deeper in that, let’s start first with opening the SciLab console and type in “scinotes”. This will open the SciLab text editor and we can finally code here. We’re making some matrices!

In the scinotes, type in


this will make a one row matrix and a one row matrix y as well. Since the two matrices are of the same size, this makes plotting a sine wave easier.


which yields


As for other matrix operations, consider the following matrices


Now look at the following operations,


Line 9 shows matrix addition. This just adds the matrices element per element. Line 10 shows matrix multiplication. This multiplies the rows element of the first matrix to the column element of the second matrix. The result is an m×n matrix where m is the number of rows the 1st matrix have and n is the number of rows the 2nd matrix. Line 11 on the other hand is a more straightforward multiplication, the dot product operation. This multiplies two matrices of similar size element per element. We will be using these in the next chapter of our journey to holes.


Step 2: Making Holes (Aperture)

Circular Hole – an Example

We were given a circular aperture as an example in class, it goes something like circcirc

We can extract information from the example given. Let’s break it down, shall we?

  1. x, y are just 1D matrices with 100 elements ranging from -1 to 1.
  2. [X,Y] is a 2D matrix that is basically a labeled Cartesian plane.
  3. r squares each matrices element per element, this r will be used to locate some points in the Cartesian plane to mask.
  4. A is created to contain a nx × ny matrix full of zeros,
  5. find() locates matrix addresses. This enables the re-initialization of values within the parameters specified.

Using these info, let’s create…

A. Centered Square

This square is also centered like the circle one. Seeing the same pattern, we can make r be a constant value being half the length of the square. This way just have to reconfigure the masking of matrix A like…


It’s all about the masking, man! NOW TO MAKE MORE FANCY HOLES!

B. Sinusoid along the x-axis (Corrugated Roof)

The heck?! Sinusoid? Chill reader! if you can’t imagine this, then here’s a visual aid for you to imagine this.


Enough imagination? Then let’s get to business. To do this, we can directly apply the mask to the X-axis like in the figure below.

Using r = sin(2πfX)

This way, the whole X-axis will be changed but Y-axis will remain unchanged resulting to…

sin sin

C. Grating along the x-axis

From the last aperture, making a grating is kind of easy. We just have to make something similar with sharp edges. To do this, we will not directly alter A but make an r matrix with the sinusoid X and locating the positions at which it has zero value like


D. Annulus

Not again! What is an annulus!?


Calm down please. Annulus is just a delicious treat. A donut! To make this, we just have to return the values of some inner circle to zero to darken it. Alas! Donut ala Archel.


E. Ellipse

This is another easy one since a circle is just a special ellipse, if we change the formula for circle to the general polar equation for ellipse:

r = √(aX² + bY²)

Then we just have to manipulate a and b to control how the ellipse will behave,


F. Cross

Another easy aperture to make, the cross can be considered to be an overlap of two rectangles.  Much like the square aperture, but only with unequal length and width for the two adjacent sides. After which, the length and width are to be reversed to make a cross!


G.  Circular aperture with graded transparency

To make a circular aperture with a graded transparency, we must use a  Gaussian Function to simulate a graded intensity. We will use the formula

{g = f(x) = ae^{(x-b)/(2c^2)}}

Where a is the amplitude of the function,  b is the offset from the center, and c corresponds to the width of the spread or standard deviation from the center. For now, we shall set all values arbitrarily to them as a =1, b =0 and 2c^2 = 100 over all. Implementing this,


 All in all, I would grade my self an 8/10 for the activity. Since I literally just went lazy on this one. Not that it is not interesting but maybe my mind is somewhere else. That has to stop. Bad AC, bad.

Despite that, I would like to thank clearlyconfusedcarlo for judging me for not working and giving me hints on how to tackle some problems.