% example usage of generate_simulated_spots and centroid_image clear all close all %% example 1 - %---------------------------------------------------------- npixels = 1024; % the number of pixels in the image digitize = 0; % =1, therefore digitize to 12-bits IntensityNoise = 0; % =0, therefore do NOT add photo-electron shot noise positionNoise = 0; % =0, therefore keep the nominal positions of the spots regular ONOFF(1).str = 'OFF'; ONOFF(2).str = 'ON'; % report disp('EXAMPLE 1') disp('---------') disp(['- Number of pixels = ', num2str(npixels)]) disp(['- 12-bit digitization is ', ONOFF(digitize+1).str]) disp(['- photo-electron shot noise is ', ONOFF(IntensityNoise+1).str]) disp(['- position-noise is ', ONOFF(positionNoise+1).str]) % generate the spot image genSpots = generate_simulated_spots(npixels, digitize, ... IntensityNoise, positionNoise); % initialize centroids - and set the background level to subtract clear centroids centroids.background = genSpots.image(1, 1); centroids = centroid_image(genSpots.image, centroids); % display the RMS deviation between the calculated centroids and the % nominal centroids diff = sort(centroids.current_centroids) - sort(genSpots.positions); RMS = sqrt(sum(diff(:, 1).^2 + diff(:, 2).^2)/numel(diff)); disp(['The RMS spot error for example 1 is ',num2str(RMS), ' pixels' ]) disp(' ') imagesc(genSpots.image); %---------------------------------------------------------- %% example 2 - %---------------------------------------------------------- npixels = 400; % the number of pixels in the image digitize = 1; % =1, therefore digitize to 12-bits IntensityNoise = 0; % =0, therefore do NOT add photo-electron shot noise positionNoise = 0; % =0, therefore keep the nominal positions of the spots regular ONOFF(1).str = 'OFF'; ONOFF(2).str = 'ON'; % report disp('EXAMPLE 2') disp('---------') disp(['- Number of pixels = ', num2str(npixels)]) disp(['- 12-bit digitization is ', ONOFF(digitize+1).str]) disp(['- photo-electron shot noise is ', ONOFF(IntensityNoise+1).str]) disp(['- position-noise is ', ONOFF(positionNoise+1).str]) % generate the spot image genSpots = generate_simulated_spots(npixels, digitize, ... IntensityNoise, positionNoise); % initialize centroids - and set the background level to subtract clear centroids centroids.background = genSpots.image(1, 1); centroids = centroid_image(genSpots.image, centroids); % display the RMS deviation between the calculated centroids and the % nominal centroids diff = sort(centroids.current_centroids) - sort(genSpots.positions); RMS = sqrt(sum(diff(:, 1).^2 + diff(:, 2).^2)/numel(diff)); disp(['The RMS spot error for example 1 is ',num2str(RMS), ' pixels' ]) disp(' '); %---------------------------------------------------------- %% example 3 - %---------------------------------------------------------- npixels = 400; % the number of pixels in the image digitize = 0; % =1, therefore digitize to 12-bits IntensityNoise = 1; % =0, therefore do NOT add photo-electron shot noise positionNoise = 0; % =0, therefore keep the nominal positions of the spots regular ONOFF(1).str = 'OFF'; ONOFF(2).str = 'ON'; % report disp('EXAMPLE 3') disp('---------') disp(['- Number of pixels = ', num2str(npixels)]) disp(['- 12-bit digitization is ', ONOFF(digitize+1).str]) disp(['- photo-electron shot noise is ', ONOFF(IntensityNoise+1).str]) disp(['- position-noise is ', ONOFF(positionNoise+1).str]) % generate the spot image genSpots = generate_simulated_spots(npixels, digitize, ... IntensityNoise, positionNoise); % initialize centroids - and set the background level to subtract clear centroids centroids.background = genSpots.image(1, 1); centroids = centroid_image(genSpots.image, centroids); % display the RMS deviation between the calculated centroids and the % nominal centroids diff = sort(centroids.current_centroids) - sort(genSpots.positions); RMS = sqrt(sum(diff(:, 1).^2 + diff(:, 2).^2)/numel(diff)); disp(['The RMS spot error for example 1 is ',num2str(RMS), ' pixels' ]) disp('NOTE: the RMS error with realistic photo-electron shot noise') disp(' will be approximately 0.1%-0.3% of a pixel') disp('') %---------------------------------------------------------- %% example 4 - %---------------------------------------------------------- npixels = 400; % the number of pixels in the image digitize = 0; % =1, therefore digitize to 12-bits IntensityNoise = 0; % =0, therefore do NOT add photo-electron shot noise positionNoise = 1; % =0, therefore keep the nominal positions of the spots regular ONOFF(1).str = 'OFF'; ONOFF(2).str = 'ON'; % report disp('EXAMPLE 4') disp('---------') disp(['- Number of pixels = ', num2str(npixels)]) disp(['- 12-bit digitization is ', ONOFF(digitize+1).str]) disp(['- photo-electron shot noise is ', ONOFF(IntensityNoise+1).str]) disp(['- position-noise is ', ONOFF(positionNoise+1).str]) % generate the spot image genSpots = generate_simulated_spots(npixels, digitize, ... IntensityNoise, positionNoise); % initialize centroids - and set the background level to subtract clear centroids centroids.background = genSpots.image(1, 1); centroids = centroid_image(genSpots.image, centroids); % display the RMS deviation between the calculated centroids and the % nominal centroids diff = sort(centroids.current_centroids) - sort(genSpots.positions); RMS = sqrt(sum(diff(:, 1).^2 + diff(:, 2).^2)/numel(diff)); disp(['The RMS spot error for example 1 is ',num2str(RMS), ' pixels' ]) disp('') %----------------------------------------------------------