so we were tasked to generate synthetic images using Scilab, a high-level programming language that can do image-processing (among other things). i however, used MATLAB (and will be using MATLAB for the rest of the semester and my life), since i’m more used to it, and i have been using it for more than half a year now. still, just because you’ve been using it for a relatively long time, doesn’t mean you’re pretty proficient with it.
anyway, this is a checklist of what images we should be able to generate:
a. centered square aperture
b. sinusoid along the x-direction
c. grating along the x-direction
d. annulus
e. circular aperture with gaussian transparency
f. ellipse
g. cross
and here’s the code:
%%%Hilado Activity 3%%% saveloc = 'D:\Random Stuff\20150820\AP 186 Act 3\'; saveext = '.png'; %%%set size of image%%% nx = 150; ny = 150; %%%create square aperture%%% x = linspace(-1,1,nx); y = linspace(-1,1,ny); A = ones(nx, ny); A(find(abs(X) > 0.4)) = 0; A(find(abs(Y) > 0.4)) = 0; figure(1); imshow(A); imwrite(A, strcat(saveloc, 'square', saveext)); %%%alternative method to creating square aperture%%% % I = ones(50,50); % I = padarray(I,[50,50]); % figure(1); imshow(I); %%%create sinusoid grid%%% x = linspace(-10,10,nx); y = sin(x); [X,Y] = ndgrid(x,y); figure(2); imshow(Y); imwrite(Y, strcat(saveloc, 'sinusoid', saveext)); %%%create square grating grid%%% y = square(x); [X,Y] = ndgrid(x,y); figure(3); imshow(Y); imwrite(Y, strcat(saveloc, 'grating', saveext)); %%%create annulus%%% x = linspace(-1,1,nx); y = linspace(-1,1,ny); [X,Y] = ndgrid(x,y); r = sqrt(X.^2 + Y.^2); A = zeros(nx, ny); A(find(r<0.7)) = 1; A(find(r<0.4)) = 0; figure(4); imshow(A); imwrite(A, strcat(saveloc, 'annulus', saveext)); %%%create circular aperture with gaussian transparency%%% sigma = 2.0; gauss = 1/(2*pi*sigma^2)*exp((-r^2)/(2*sigma^2)); gauss = gauss./sum(gauss(:)); figure(5); imshow(mat2gray(gauss)); imwrite(gauss, strcat(saveloc, 'gaussian', saveext)); %%%create ellipse%%% a = 1; b = 1.5; ellipse = (X/a).^2 + (Y/b).^2; ellipse./sum(ellipse(:)); A = zeros(nx,ny); A(find(ellipse<0.4)) = 1; figure(6); imshow(A); imwrite(A, strcat(saveloc, 'ellipsis', saveext)); %%%create cross%%% A = zeros(nx,ny); A(find(abs(X)<0.3)) = 1; A(find(abs(Y)<0.3)) = 1; figure(7); imshow(A); imwrite(A, strcat(saveloc, 'cross', saveext));
and here are the corresponding synthetic images:
I would give myself a 10/10, for doing all the required output.