For the second activity we had a bit of practice in using the SciLab programming language.
We had to produce the following synthetic images: a. b. c. d. e. Centered square aperture Sine wave along x direction (corrugated roof) Grating along x direction Annulus Circular aperture with graded transparency (Gaussian function)
But first we had to follow a sample code given by Dr. Soriano. The code produced a 100 x 100 pixel image of a centered circular aperture with radius of 35 pixels (Figure 1).
nx = 100; ny = 100; //defines the number of elements along x and y x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates r= sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y A = zeros (nx,ny); A (find(r<0.7) ) = 1; imshow (A);
Centered circular aperture (r = 35pixels)
After doing the centered circular aperture I am ready to do the other synthetic images. The easiest to do was the annulus since you just have to tweak the code for the centered circular aperture. I just replaced line 7 of the code with: A(find(r<0.7 & r>0.3)) = 1. This logical statement would only return True for regions between circles with r<0.7 and r>0.3, hence, only this interval would have a value 1 giving us an annulus (Figure 2). To change the thickness of the annulus, you just have to change the values for the radii. I used 500 x 500 pixels for my array and image dimensions for this and all the other images.
nx = 500; ny = 500; //defines the number of elements along x and y x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates r1 = sqrt(X.^2 + Y.^2); A1 = zeros (nx,ny); A1 (find(r1<0.7 & r1>0.3)) = 1; //creates annulus imwrite(A1, "annulus_0.4.png");
Annulus (thickness = 200pixels)
The centered square aperture was fairly easy to do. Its still similar to that of the centered aperture but this time you have to find values of x and y that are less than a certain value s which corresponds to the length of a side. The code and the resulting image is shown in Figure 3.
nx = 500; ny = 500; //defines the number of elements along x and y x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates A = zeros (nx,ny); s = 0.5; A (find(abs(X)<s & abs(Y)<s) )= 1; //create square with side s imwrite(A, 'square_aperture_0.7.png');
Centered square aperture (250 x 250 pixels)
Next is the corrugated roof done using a sine function along the x-direction. The code and results are found in Figure 4.
//sinusoid along x direction (corrugated roof) x1 = linspace(-3, 4, 500); //range of x values y1 = ndgrid(x1,x1); y1 = y1; //transpose y1 such that values are increasing along the x axis sine_wave = sin(%pi*y1); imwrite(sine_wave', "sine_wave.png");
Sinusoid along x direction To create the grating, I used a sinusoid along the x direction. I just replaced the values in the matrix that are greater than 0 with 1, and those less than or equal to 0 with 0. The code and results are shown below (Figure 5).
//grating along x direction x2 = linspace(-3*%pi, 4*%pi, 500); y2 = sin(x2); grating = ndgrid(y2,y2); grating(find(grating>0))= 1; //replace values>0 with 1 grating(find(grating<=0))= 0; //replace values<=0 with 0 imwrite(grating', "grating.png");
Grating along x direction
Finally, for the circular aperture with graded transparency, I just multiplied the aperture matrix with the Gaussian mask matrix which I produced by using the Gaussian function. For different values of the parameter c,which gives the variance of the Gaussian function, the resulting image also varies. Code and image found in Figure 6.
nx = 100; ny = 100; //defines the number of elements along x and y x = linspace(-1,1,nx); //defines the range y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates r2 = sqrt(X.^2 + Y.^2); A2 = zeros (nx,ny); A2 (find(r2<0.7)) = 1; a = 1; b=0; c=0.4; gaussian = a*exp (-(r2-b).^2/(2*c^2)); //Gaussian function imwrite(A2.*gaussian, "masked_aperture_0.4.png");
Circular aperture with graded transparency (Gaussian function) Aperture radius = 350 pixels Variance = 0.4