-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinitegausspsf.m
72 lines (60 loc) · 1.8 KB
/
finitegausspsf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
%finiteGaussPSFerf Make Gaussian Spots using finite pixel size
%
% [out] = finitegausspsf(Npixels,sigma,I,bg,cor)
%
% INPUT
% Npixels: linear size in pixels
% sigma: PSF sigma in pixels, scaler gives symmetric, [sx sy] gives
% asymmetric.
% I: Photons/frame
% bg: background/pixel
% cor: coordinates array size of [2 N] where N is number of spots
% to generate.
%
% OUTPUT
% out: 3D stack of images.
function [out] = finitegausspsf(Npixels,sigma,I,bg,cor)
calcInt=1;
if (nargin < 5)
cor = [(Npixels-1)/2 (Npixels-1)/2 0];
end
if (nargin <4)
error('Minimal usage: finitegausspsf(Npixels,sigma,I,bg)');
end
if (bg == 0)
bg = 10^-10;
end
Ncor=size(cor,1);
x=repmat((0:Npixels-1)',[1 Npixels]);
y=x';
X=repmat(x,[1 1 Ncor]);
Y=repmat(y,[1 1 Ncor]);
Xpos=repmat(shiftdim(cor(:,1),-2),[Npixels,Npixels,1]);
Ypos=repmat(shiftdim(cor(:,2),-2),[Npixels,Npixels,1]);
if size(I,1) > 1
I=repmat(shiftdim(I,-2),[Npixels,Npixels,1]);
if max(size(Xpos) ~= size(I))
error('Size of I and maybe others are incorrect.');
end
end
if size(bg,1) > 1
bg=repmat(shiftdim(bg,-2),[Npixels,Npixels,1]);
if max(size(Xpos) ~= size(bg))
error('Size of bg and maybe others are incorrect.');
end
end
if length(sigma)==1
sigmay = sigma;
sigmax = sigma;
else
sigmax = sigma(1);
sigmay = sigma(2);
end
if calcInt
gausint=I/4.*((erf((X-Xpos+.5)./(sqrt(2)*sigmax))-erf((X-Xpos-.5)./(sqrt(2)*sigmax))).*...
(erf((Y-Ypos+.5)./(sqrt(2)*sigmay))-erf((Y-Ypos-.5)./(sqrt(2)*sigmay))))+bg;
else
gausint = I/(2*pi*sigmax*sigmay)*exp(-1/2*((X-Xpos)/sigmax).^2).*exp(-1/2*((Y-Ypos)/sigmay).^2)+bg;
end
out=gausint;
end