(Welcome, Interwebs traveler. A note before you go: please click any image to view in enlarged/theater mode. Now explore on!)
Today's activity focused on basic matrix operations in Scilab, particularly addition, subtraction and multiplication. We were first tasked to download and test Scilab; however, since my computer already had a working copy of MATLAB (which, according to Wikipedia, is similar in syntax to Scilab), I had chosen to work on MATLAB for this activity.
| Figure 1. Code used to test the functionality of the program. |
The test code was given as shown in Figure 1, which would produce a sinusoidal curve in a 2-D plot (shown in Figure 2). The program was shown to be functional if the test code was successful, which it indeed was for my case.
![]() |
| Figure 2. Plot produced by the test code in Figure 1. The program was deemed functional if the plot was successfully produced, as in this case. Thus, my program was functional. |
Synthetic Images
For our practice with the program, we were tasked to create six synthetic images.
Centered Circle
![]() |
| Figure 3. Synthetic image of a centered circle. This was the image I produced with my code in Figure 4. |
The first was a centered circle. The code was provided for this figure, which could be used in research to simulate a circular aperture or pinhole as described in the handout. Figure 4 shows the translated MATLAB code, and Figure 3 is the image I produced using the code.
| Figure 4. Translated MATLAB code used to produce a white circle of radius r < 0.7 centered on a black background. |
Centered Square
![]() |
| Figure 5. Synthetic image of a centered square. This was the image I produced with my code in Figure 6. |
The second figure was a centered square. The white square centered on a black background in Figure 5 was produced by me using the code in Figure 6.
Sinusoid
![]() |
| Figure 7. Synthetic 2-D image of a sinusoid along the x-axis. This was the image I produced using my code in Figure 11. |
![]() |
| Figure 8. Synthetic 3-D image of a sinusoid along the x-axis. |
The next synthetic image was sinusoid along the x-axis. Figure 7 is the 2-D synthetic image I produced, and Figure 8 is the 3-D synthetic image.
![]() |
| Figure 9. Synthetic 2-D image of a sinusoid along the y-axis. This was the image I produced using my code in Figure 11. |
![]() |
| Figure 10. Synthetic 3-D image of a sinusoid along the y-axis. |
Additionally, I produced its 2-D and 3-D counterpart along the y-axis, shown by Figures 9 and 10, respectively. The code for these sinusoids is found in Figure 11.
| Figure 11. MATLAB code used to produce the 2-D synthetic images of the sinusoids along the x- and y- axes. |
Grating
![]() |
| Figure 12. Synthetic image of a grating along the x-axis. This was the image I produced using my code in Figure 14. |
![]() |
| Figure 13. Synthetic image of a grating along the y-axis. This image was also produced using the code in Figure 14. |
The grating in Figure 12, which is oriented along the x-axis, (and additionally the grating in Figure 13, oriented along the y-axis) was generated using the code in Figure 14.
At first glance, it would seem that the gratings in Figs. 12 and 13 are simply sinusoids (as in Figs. 7 and 9) with larger frequency. We compare zoomed segments from Figs. 7 and 12 to determine the difference between the two. Figure 15 is a zoomed segment from Fig. 7, while Figure 16 is a zoomed segment from Fig. 12 above. It is easily seen that the sinusoid has values from 0, 1 and in between (shown as black, white and shades of gray respectively) while the grating has only two values, 0 (shown as black) and 1 (shown as white).
![]() |
| Figure 16. Zoomed segment from the grating in Fig. 12. It can be seen that the image is of alternating lines of black (or value 0) and white (or value 1) with no intermediate values. |
Annulus
The annulus is Latin for little ring. So for this synthetic image, I took the white circle centered on a black background in Fig. 3 and added a concentric black circle of smaller radius. Figure 17 shows the annulus I produced using my MATLAB code in Figure 18.
![]() |
| Figure 17. Synthetic image of an annulus. This was the image I produced using my code in Figure 18. |
| Figure 18. MATLAB code used to produce the white annulus of outer radius r < 0.7 and inner radius r > 0.4 centered on a black background. |
Circular Aperture with Graded Transparency
For this synthetic image, we were tasked to create a circle aperture with a graded transparency. This involved using a Gaussian function as the transparency, resulting in the aperture in Figure 19 as produced by the code in Figure 20.
![]() |
| Figure 19. Synthetic image of a white circular aperture with a graded transparency, centered on a black background. This was the image I produced using the code in Figure 20. |
| Figure 20. MATLAB code for the white circular aperture with graded transparency, centered on a black background. |
Exploration
The exploration activity suggested we make use of matrix operations on the synthetic images we had produced. Below are the results I obtained from adding, subtracting and multiplying my synthetic images. They are fun to look at, take a look for yourself! :)
The summary of images for this Exploration is available in this PDF (link to be added soon) for better viewing of images.
Addition
For the addition of synthetic images, I made use of the formula
Equation 1:
$P = test + A$
where test is a variable assigned with a certain synthetic image, A is a set synthetic image and P is the new image formed by matrix addition. Figure 21 shows the summary of synthetic images produced.
| Figure 21. Summary of synthetic images produced by addition. These are the images I produced using the code in Figure 22. |
Figure 22 gives a preview of the code I used to generate these images. The synthetic images (circle, square, annulus, etc.) were assigned letter names in the code. To add these images, I had devised lines of code per image that would add it to a test image. For example, to add the test image to the centered circle A, the code reads $add0 = test + A$ followed by code to show and save the image. The code is similarly structured for all synthetic images A to H.
Figure 22. Preview of the MATLAB code used to produce the added images. The previous synthetic images were labed from A to H, and were placed as the test image to be added to each synthetic image. |
Subtraction
For the subtraction of the synthetic images, I tested two formulas: one where the test image was the minuend (Equation 2), and one where the test image was the subtrahend (Equation 3). Equation 2 reads:
Equation 2:
$P = test - A$
where test is a variable assigned as the synthetic image being investigated, A is a set synthetic image and P is the new synthetic image produced using subtraction. Figure 23 is a summary table of the images I produced in this manner. Note that the row headers (from top to bottom) are the minuend (or the test images) while the column headers (from left to right) are the subtrahend.
| Figure 23. Summary table of synthetic images produced by subtraction, where the row headers are the minuend. The code for these images is not shown, but is similar to that in Figure 25. |
Figure 24 is a summary of synthetic images produced using the equation
Equation 3:
$P = A - test$
where everything is similar to Equation 2 with the exception that the test synthetic image is now the subtrahend. Figure 25 gives a preview of the code used to produce these images.
| Figure 24. Summary table of synthetic images produced by subtraction, where the row headers are the subtrahend. These are the images I produced using the code in Figure 25. |
Multiplication
For the multiplication of two synthetic images, I performed element-per-element multiplication, where in one case the test image was the multiplicand (as in Equation 4) and in the other case it was the multiplier (as in Equation 5).Figure 26 gives the summary of the synthetic images produced by element-per-element multiplication where the test image is the multiplicand.
Figure 27 is the summary table showing the synthetic images produced using element-per-element multiplication where the test images are the multipliers. It should be noted that the results are exactly the same as in Figure 26, except for the result for the gradient image multiplied with itself.
| Figure 27. Summary table of synthetic images produced by element-per-element multiplication where the row headers are the multipliers. These are the images I produced using the code in Figure 28. |
Figure 28 gives a preview to the code I used for the element-per-element multiplication.
Figure 28. Preview of the MATLAB code I used to produce the multiplied images. The previous images were labeled from A to H, and were placed as either the test multiplicand or the test multiplier. |
Grading
Based on the criteria, I give myself 5/5 for technical correctness because I believe I was able to accomplish the necessary activity. For quality of presentation, I give myself 5/5 for what I think is a clean and complete blog post (yay). For initiative, I give myself 1/2 for the additional Exploration activity.
Overall, I give myself a grade of 11/10.
As for my feelings toward the activity, I think it was an interesting and cool activity, particularly in the Exploration, because blending images together through the matrix operations was exciting -- the images came out different every time!
[ Acknowledgements: I would like to thank Norman Mascariñas who assisted me in adding LaTeX capabilities to my blog (although LaTeX refuses to work except for inline equations :( ).
I would also like to mention the following sources for different reasons:
- This Applied Physics 186 blog for giving me an idea on what a sine along the x-axis (or corrugated roof) should look like, way before Ma'am Jing arrived to explain the same; and,
- This PDF file on the Gaussian function for reminding me the proper equation for a 2-D Gaussian function, which I used in the circular aperture with graded transparency.
End Acknowledgements. :) ]













No comments:
Post a Comment