function [spot,spot_size,spot_vol_bkg,spot_vol_no_bkg] = gen2dgauss(n,varx,vary, max_gray,min_gray,resolution,file_name); %n is the square in which the gaussian is to be placed %varx is the variance along the x axis %vary is the variance along the y axis %max_gray is the maximum gray level desired at the spot center %min_gray is the minimum gray level desired as the background %resolution is the dpi resolution required for the tiff file to which we %write. %file_name is the strng that gives the file name to write %2-D gaussian is given by % 1/((2*pi)^(N/2)*|A|^(1/2)) exp-(1/2( (x-mx)'*A^(-1)*(y-my))) %initialize the spot spot = zeros(n,n); %find the mean along the x and y axes x_mean = ceil(n/2); y_mean = ceil(n/2); %whether or not to insert side spots insert_side_spots = 1; %defining the covariance matrix var = [varx 0 0 vary]; %computing the determinant of the covariance matrix det_var = varx*vary; %computing the inverse of the covariance matrix inv_var = [(1/vary) 0 0 (1/varx)]; %determining the peak of the gaussian max_val = (1/(2*pi*sqrt(det_var))); for x = 1:n for y = 1:n %the 2-d vector corresponding to the 2 dimensions Z = [(x-x_mean) (y-y_mean)]; spot(x,y) = (1/(2*pi*sqrt(det_var)))*exp(-(1/2)*(Z.')*inv_var*Z); end end %normalizing and scaling the gaussian spot = round(((max_gray-min_gray)*spot./max_val)+min_gray); spot_size = sum(sum(spot>min_gray)); spot_vol_bkg = sum(sum(spot(spot > min_gray))); spot_vol_no_bkg = sum(sum(spot(spot > min_gray))) - min_gray*spot_size; if(insert_side_spots) %mean of the side spots at the four corners side1_x_mean = ceil(n/8); side1_y_mean = ceil(n/8); side2_x_mean = ceil(7*n/8); side2_y_mean = ceil(n/8); side3_x_mean = ceil(n/8); side3_y_mean = ceil(7*n/8); side4_x_mean = ceil(7*n/8); side4_y_mean = ceil(7*n/8); side5_x_mean = ceil(n/2); side5_y_mean = ceil(n/8); side6_x_mean = ceil(7*n/8); side6_y_mean = ceil(n/2); side7_x_mean = ceil(n/2); side7_y_mean = ceil(7*n/8); side8_x_mean = ceil(n/8); side8_y_mean = ceil(n/2); side9_x_mean = ceil(n/4); side9_y_mean = ceil(n/4); side10_x_mean = ceil(3*n/4); side10_y_mean = ceil(n/4); side11_x_mean = ceil(3*n/4); side11_y_mean = ceil(3*n/4); side12_x_mean = ceil(n/4); side12_y_mean = ceil(3*n/4); varx_side = 40; vary_side = 40; var_side = [varx_side 0 0 vary_side]; %computing the determinant of the covariance matrix det_var_side = varx_side*vary_side; %computing the inverse of the covariance matrix inv_var_side = [(1/vary_side) 0 0 (1/varx_side)]; %determining the peak of the gaussian max_val = (1/(2*pi*sqrt(det_var_side))); for x = 1:n for y = 1:n %the 2-d vector corresponding to the 2 dimensions Z = [(x-side1_x_mean) (y-side1_y_mean)]; side1_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side2_x_mean) (y-side2_y_mean)]; side2_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side3_x_mean) (y-side3_y_mean)]; side3_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side4_x_mean) (y-side4_y_mean)]; side4_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side5_x_mean) (y-side5_y_mean)]; side5_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side6_x_mean) (y-side6_y_mean)]; side6_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side7_x_mean) (y-side7_y_mean)]; side7_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side8_x_mean) (y-side8_y_mean)]; side8_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side9_x_mean) (y-side9_y_mean)]; side9_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side10_x_mean) (y-side10_y_mean)]; side10_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side11_x_mean) (y-side11_y_mean)]; side11_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); Z = [(x-side12_x_mean) (y-side12_y_mean)]; side12_spot(x,y) = (1/(2*pi*sqrt(det_var_side)))*exp(-(1/2)*(Z.')*inv_var_side*Z); end end %normalizing and scaling the gaussian side1_spot = round(255*(side1_spot./max_val)); %normalizing and scaling the gaussian side2_spot = round(255*(side2_spot./max_val)); %normalizing and scaling the gaussian side3_spot = round(255*(side3_spot./max_val)); %normalizing and scaling the gaussian side4_spot = round(255*(side4_spot./max_val)); %normalizing and scaling the gaussian side5_spot = round(255*(side5_spot./max_val)); %normalizing and scaling the gaussian side6_spot = round(255*(side6_spot./max_val)); %normalizing and scaling the gaussian side7_spot = round(255*(side7_spot./max_val)); %normalizing and scaling the gaussian side8_spot = round(255*(side8_spot./max_val)); %normalizing and scaling the gaussian side9_spot = round(255*(side9_spot./max_val)); %normalizing and scaling the gaussian side10_spot = round(255*(side10_spot./max_val)); %normalizing and scaling the gaussian side11_spot = round(255*(side11_spot./max_val)); %normalizing and scaling the gaussian side12_spot = round(255*(side12_spot./max_val)); side_spot = side1_spot + side2_spot + side3_spot + side4_spot + side5_spot + side6_spot + side7_spot + side8_spot + side9_spot + side10_spot + side11_spot + side12_spot; spot = spot + side_spot; spot(spot>255) = 255; end %inverting : because the spot is such that it is white at the center and black towards %the tails and what we want is black at the center and white towards the tails spot = 255 - spot; spot = uint8(spot); image(spot); colormap('gray'); axis equal; xlim([1 n]); ylim([1 n]); axis off; file_name = strcat(file_name,'.tif'); imwrite(spot,file_name,'tif','Compression','none','Resolution',resolution);