-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsimulate2c.m
80 lines (65 loc) · 2.29 KB
/
simulate2c.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
73
74
75
76
77
78
79
80
function out=simulate2c
% transformfile='/Users/jonas/Documents/Data/ROI2_20per639_50msexp_1/ROI2_20per639_50msexp_1/ROI2_20per639_50msexp_1_MMStack2_T.mat';
cal3dfile='/Users/jonas/Documents/Data/ROI2_20per639_50msexp_1/ROI2_20per639_50msexp_1_3dcal.mat';
% transformfile='/Users/jonas/Documents/Data/ROI2_20per639_50msexp_1/simulstack_affine_2_T.mat';
transformfile='/Users/jonas/Documents/Data/ROI2_20per639_50msexp_1/affine_T.mat';
% transformfile='/Users/jonas/Documents/Data/ROI2_20per639_50msexp_1/testmirrorA_T.mat';
% cal3dfile='/Users/ries/Documents/Data/3D/global3D/ROI2_20per639_50msexp_1_3dcal.mat';
% transformfile='/Users/ries/Documents/Data/3D/global3D/ROI2_20per639_50msexp_1/ROI2_20per639_50msexp_1_MMStack_T.mat';
mirror=true;
midp=255;
nbeads=25;
roisize=31;
dr=(roisize-1)/2;
zpos=1:201; %in slices
% zpos=99:101;
pixelsize=100;
Nphot=16000;
Nbg=5;
img=zeros(512,512,length(zpos),'single');
x=rand(nbeads,1)*(size(img,1)-roisize*2)+roisize;
y=rand(nbeads,1)*(size(img,2)-roisize*2)/2+roisize;
xnm=x*pixelsize; ynm=y*pixelsize;
t=load(transformfile); transformation=t.transformation;
t=load(cal3dfile); coeffh=t.SXY.cspline.coeff;
% coeff=coeffh;
coeff{1}=coeffh;coeff{2}=coeffh;
[xtnm,ytnm]=transformation.transformCoordinatesFwd(xnm,ynm);
xt=xtnm/pixelsize;yt=ytnm/pixelsize;
figure(88);plot(x,y,'+',xt,yt,'x')
% coord=horzcat(y,x);
coord=horzcat(x,y);
channel=1;
makeimg;
% coord=horzcat(yt,xt);
coord=horzcat(xt,yt);
channel=2;
makeimg
img=img+Nbg;
if mirror
img(midp:end,:,:)=img(end:-1:midp,:,:);
end
imageslicer(img);
imgnoise=poissrnd(img);
outfile=[fileparts(cal3dfile) filesep 'simulstackM.tif'];
outfile2=[fileparts(cal3dfile) filesep 'simulstackMp.tif'];
% imgnoise=permute(imgnoise,[2,1,3]);
saveastiff(uint16(imgnoise),outfile);
saveastiff(uint16(img+Nbg),outfile2);
function makeimg
roipos=round(coord);
incoord=coord-roipos+dr;
incoord(:,[1 2])=incoord(:,[2 1]);
incoord(:,4)=Nphot;
incoord(:,5)=0;
for zk=1:length(zpos)
incoord(:,3)=zpos(zk);
impsf=renderPSF(coeff{channel},incoord,roisize);
for k=1:nbeads
if all(roipos(k,:)>dr)&&all(roipos(k,:)<size(img,1)-dr+1)
img(roipos(k,2)-dr:roipos(k,2)+dr,roipos(k,1)-dr:roipos(k,1)+dr,zk)=img(roipos(k,2)-dr:roipos(k,2)+dr,roipos(k,1)-dr:roipos(k,1)+dr,zk)+impsf(:,:,k);
end
end
end
end
end