File Exchange

image thumbnail

Create a Simulated Image of Diffraction Limited Spots with Noise

version 1.0.0.0 (2.93 KB) by Tristan Ursell
Create images with diffraction-limited spots of varying size and intensity, with noise.

3 Downloads

Updated 04 Apr 2012

View License

Tristan Ursell
March 2012

Create an image with randomly positioned, diffraction-limited spots with full data on actual spot positions and parameters. Useful for testing a spot finding algorithm.

[Iout,Inoise,spot_data]=spotmaker([im_sz],num_spots);
[Iout,Inoise,spot_data]=spotmaker([im_sz],num_spots,'field',value);

im_sz = two column vector specifying the size (rows,columns) of the output image.

num_spots = integer value number of spots to appear in the image.

Iout = full output image, with spots and noise according to all specified parameters.

Inoise = only the noise that appears in Iout.

The output 'spot_data' is a structure array with fields:

spot_data.Xcent(i) = x-center of the Gaussian spot i.
spot_data.Ycent(i) = y-center of the Gaussian spot i.
spot_data.ints(i) = peak height (intensity) of the Gaussian spot i.
spot_data.stds(i) = peak width (STD) of the Gaussian spot i.

length(spot_data.Xcent) = number of spots

The possible field entries are:

'spot_pos' is an optional specification of where the spots should occur in the image. The input should be a two column matrix of X and Y positions. Regardless of the value of 'num_spots', the script will use: num_spots = length(X).

'noise_mu' (-Inf < noise_mu < Inf) is the mean intensity of Gaussian noise in the output image. The default value is 0.

'noise_std' (0 < noise_std < Inf) is the standard deviation of the Gaussian noise in the output image. The default value is 0.

'int_mu' (0 < int_mu < Inf) is the mean spot intensity. The default value is 1.

'int_std' (0 < int_std < Inf) is the standard deviation in spot intensity. The default value is 0.

'wid_mu' (0 < wid_mu < Inf) is the mean width of the spot intensity distribution. The default value is 4.

'wid_std' (0 < wid_std < Inf) is the standard deviation in the widths of the spot intensity distributions. The default value is 0.

'plot' with value 1 will produce an output plot of Iout with the spot centers marked by red circles.

%Simple Example:
[Iout,Inoise,spot_data]=spotmaker([400,500],200,'plot',1);

%More Complex Example:
[Iout,Inoise,spot_data]=spotmaker([400,500],200,'plot',1,'noise_mu',100,...
'noise_std',20,'int_mu',100,'int_std',20,'wid_std',1);

%Specified Position Example:
Xin=linspace(10,400,10)';
Yin=linspace(10,300,10)';

[Iout,Inoise,spot_data]=spotmaker([320,420],200,'spot_pos',[Xin,Yin],'plot',1,...
'noise_mu',100,'noise_std',20,'int_mu',100,'int_std',20,'wid_std',1);

%write to 8 bit output image:
imwrite(uint8(255*mat2gray(Iout)),'spot_test.tif','Compression','none')

Comments and Ratings (3)

Thank you for this, very helpful

Abani Nayak

sir
i am sorry to put you in trouble. i myself figured it out how to do that. i had not checked the imwrite function at that time.
thank you sir for your beautiful code. it will help me a lot in my project.

Abani Nayak

sir
i am new to the matlab. i am doing a similar project. this program was very helpful to me. while running the examples given above by you. i am getting the spots enclosed with red circles. i want the image as it is but without the red circle. i did some modification with your code but i couldn't find any solutions to my problem.
so i request yo to kindly help me to get the spots but without red circles enclosing the spot.
Thank you

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux