Similar to activity 2, I was able start with activity 3 last August 24 for the same reasons. Since ma'am was no able to attend class that time, I chose to work on the activities in our laboratory and work on it independently.
Activity 3 involves the use of Scilab, which is a very powerful programming language advantageous for matrix calculations. The activity serves as an introduction to Scilab employing some of its basic commands, which shall be vital since the activities will become more avanced as the semester progresses.
In this activity, we were tasked to synthesize images using Scilab. Images are represented as matrices so we exploit the capabilities of Scilab to do this. A sample code was given which produces a centered circular aperture as shown below.
Centered circular aperture |
The sample code was very helpful in serving as a basis on how to produce the listed target images, which were: centered square aperture, sinusoid along the x (corrogated roof-like pattern), grating along the x, annulus, circular aperture with a Gaussian transparency, cross, and an ellipse. Of course, as most of the time, I also seeked help from a very good friend -- Google. I searched for some of the commands and syntax of Scilab, which mostly led me to the help.scilab.org website. The synthesized images are shown below
Centered square aperture |
Sinusoid along the x-axis (corrogated roof-like pattern) |
Grating along the x-axis |
Annulus |
Circular aperture with a Gaussian transparency |
Ellipse |
Centerd circular aperture + centered square aperture |
Circular aperture with Gaussian transparency - annulus |
Annulus * centered circular aperture |
Sinusoid along the x-acis .* grating along the x-axis |
Aside from the prescribed images to be synthesized, I also synthesized an image of a pokeball, inspired by the currently trending game Pokemon Go. At first, I thought that the synthesis of this image would be difficult. But due to the symmetry of the image and the similarity of the patterns to the images above, I was able to produce the image as shown below.
Pokeball |
The activity was fun yet very helpful. Having used Scilab last semester just briefly, this activity has helped me to review what I already know about Scilab, learn new things about the language, and further engrave in my mind the things-to-know about Scilab. I am excited about further lessons involving the use of Scilab in a more advanced topic. For this activity, maybe I will give my self a grade of 11. I was able to produce all the listed target images, along with other images employing matrix operations and, in addition, a pokeball. I think that the images are also presented well.
I have included the code which produced the images above, for the reference of those who want to produce such or similar patterns.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | nx = 100 ; ny = 100 ; x = linspace(-1,1,nx); y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); // Centered circular aperture r = sqrt(X.^2 + Y.^2); A = zeros(nx,ny); A(find(r<0.7)) = 1; f = scf(); grayplot(x,y,A); f.color_map = graycolormap(32); // Centered square aperture B = zeros(nx,ny); B((nx/2)-(nx/4):(nx/2)+(nx/4), (ny/2)-(ny/4):(ny/2)+(ny/4))=1; f2 = scf(); grayplot(x,y,B); f2.color_map = graycolormap(32); // Sinusoid along the x-direction C = sin(30*X); f3 = scf(); grayplot(x,y,C); f3.color_map = graycolormap(32); // Grating along the x-direction D = zeros(nx,ny); D(:,1:5:100) = 1; f4 = scf(); grayplot(x,y,D); f4.color_map = graycolormap(32); // Annulus r1 = sqrt(X.^2 + Y.^2); E = zeros(nx,ny); E(find(r1>0.3 & r1<0.7)) = 1; f5 = scf(); grayplot(x,y,E); f5.color_map = graycolormap(32); // Circular aperture with Gaussian transparency r3 = sqrt(X.^2 + Y.^2); F1 = zeros(nx,ny); F1(find(r<0.7))=1 ; F2 = exp(-(X.^2 + Y.^2)/0.05); F = F1.*F2; f6 = scf(); grayplot(x,y,F); f6.color_map = graycolormap(32); // Ellipse a = max(x)/2; b = max(y)/4 ; r4 = (X.^2 / a^2) + (Y.^2 / b^2); G = zeros(nx,ny); G(find(r4<1)) = 1; f7 = scf(); grayplot(x,y,G); f7.color_map = graycolormap(32); // Cross H = zeros(nx,ny); H((nx/2)-(nx/4):(nx/2)+(nx/4),(ny/2)-(ny/8):(ny/2)+(ny/8)) = 1; H((nx/2)-(nx/8):(nx/2)+(nx/8),(ny/2)-(ny/4):(ny/2)+(ny/4)) = 1; f8 = scf(); grayplot(x,y,H); f8.color_map = graycolormap(32); // Circular aperture + square aperture f9 = scf(); grayplot(x,y,A+B); f9.color_map = graycolormap(32); // Sinusoid along the x direction .* grating along the x f10 = scf(); grayplot(x,y,C.*D); f10.color_map = graycolormap(32); // Annulus * circular aperture f11 = scf(); grayplot(x,y,E*A); f11.color_map = graycolormap(32); // Pokeball r5 = sqrt(X.^2 + Y.^2); P = zeros(nx,ny); P(find(r<0.2))=1; P(find(r>0.3 & r<0.8))=1; P(:,48:53) = 0; P(find(r<0.2))=1; P(find(r>0.1 & r<0.13))=0; f12 = scf(); grayplot(x,y,P); f12.color_map = graycolormap(32); |
No comments:
Post a Comment