As an introduction to learning the basics of Scilab, we were tasked to generate synthetic images using matrix operations in Scilab.
First off, we have the centered square aperture. I found this to be relatively straightforward.
Figure 1. Code (bottom) and generated image (top) of the square aperture.
The first five lines of the code are responsible for generating a 2D grid wherein each point in the grid is assigned an x and y coordinate pair. The maximum and minimum value for both x and y coordinates were 1 and -1, accordingly. The generation of the 2D grid is handled by the meshgrid() function where x and y are the "template" vectors of the grid. As shown in Figure 1, The size of the square aperture can be varied by varying the parameter a. Of course, a must be between 0 and 1 for an aperture to even exist at all.
Next up, the sinusoid along the x-axis.
Figure 2. Code (bottom) and generated image (top) of the sinusoid along the x-axis.
The code takes advantage of the way meshgrid() works. Instead of generating a 2D grid containing an xy coordinate system, a 1D array of sine values (x) was generated and then replicated across all rows of a new matrix (because you want a sinusoid along the x-axis) . Again, the frequency of the sine wave can be altered by altering the value of w.
Although physically simpler, I had to put some thought before constructing the code to generate the rectangular grating along the x-direction. After some time, I realized I could just modify the sinusoid code. After all, the only difference between the two was that the change between "black" and "white" regions had to be abrupt for the grating case. I used the find() feature to do this.
Moving on, I modified the code given to us during class to generate a circular aperture [1]. The only change needed was to alter the condition within find() to point to the region between two radii instead of one.
Figure 4. Code (bottom) and generated image (top) of the annulus
For a circular aperture with a gaussian transparency, I once again modified the circular aperture [1] code() in a way to include gaussian transparency. The code works obtaining a radial coordinate r (as was done for the annulus and circle codes [1]) using the x and y grid coordinates generated wherein the "origin" is set at the center of the grid (where x and y are 0). A (the grid to be plotted) is then populated using the gaussian function with parameter a and the radial coordinates r (line 12). To define the boundary of the aperture, a find function is used to set all values outside a radius of b to be zero (line 13).
Figure 5. Code (bottom) and generated image (top) of the circular aperture with gaussian transparency
Figure 6. Code (bottom) and generated image (top) of the elliptical aperture
Finally, I modified the square aperture code to create a cross aperture. This was done simply by modifying the parameters to create rectangular apertures instead and then including an additional find() function.
Figure 7. Code (bottom) and generated image (top) of the cross aperture
After a quick search online, I found several other blogs where students of past years got pretty creative with their images. After seeing several "rotated" images, I set to try to use the rotation matrix to try to generate my own rotated ellipse. The result is below.
As shown above, the code is similar to that of the ellipse. The big difference, however, lies in the fact that a rotation matrix (line 83) is introduced. Each pair of X and Y coordinates are accessed and then multiplied with the rotation matrix to produce rotated coordinates. In effect, the entire grid is being rotated. The condition for the ellipse still follows with the definition of r in line 98.
I explored rotating, adding, subtracting, and multiplying different generated images to obtain the following. Can you guess which operations led to which figures?
Figure 9. Figures generated by performing different operations between the figures already generated.
Based on my performance this activity, I would rate myself a 10 out of 10. I really enjoyed and explored the use of the rotation matrix in generating more complex images. Moreover, I can say with a little more confidence now that I'm pretty familiar with programming in Scilab.
Acknowledgements:
I'd like to acknowledge Martin Bartolome's blog [2] where I first got the idea to use a rotation matrix and subsequently, Mario Onglao, Martin's source.
References:
[1] M. Soriano, "Scilab Basics," Applied Physics 186 Activity Hand-outs, 2015
[2] Activity #3 – Scilab Basics. (2015). Retrieved August 29, 2016, from https://barteezy.wordpress.com/2015/08/22/activity-3-scilab-basics/