-
Notifications
You must be signed in to change notification settings - Fork 9
/
Step2_IDT_Poss.m
123 lines (88 loc) · 3.64 KB
/
Step2_IDT_Poss.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
%%%%% IDT poss after LED Postion calibtion %%%%%
% apply calibrated
if Calib==1
Ini_NAx=(freqXY3(:,2)'-(Cablib_Nx/2+1))/Cablib_Nx/Pixelsize;
Ini_NAy=(freqXY3(:,1)'-(Cablib_Ny/2+1))/Cablib_Ny/Pixelsize;
else
TempNA=Ini_NAx;
Ini_NAx=-Ini_NAy;
Ini_NAy=TempNA;
end
% correct frequency coord of LED
Ini_PixelShiftx=zeros(1,Length_MN);
Ini_PixelShifty=zeros(1,Length_MN);
for i=1:Length_MN
pic_pos=i;
Ini_PixelShiftx(pic_pos)=round(Ini_NAx(pic_pos)*Pixelsize*Nx);
Ini_PixelShifty(pic_pos)=round(Ini_NAy(pic_pos)*Pixelsize*Ny);
end
%% Generate Complex or pure phase 3D object, and correspoding intensity bright field iamges
disp('Calculating slice-wise transfer functions...');
PTF_4D=single(zeros(Nx,Ny,length(Depth_Set),Length_MN));
ATF_4D=single(zeros(Nx,Ny,length(Depth_Set),Length_MN));
PTF_3D=single(zeros(Nx,Ny,length(Depth_Set)));
ATF_3D=single(zeros(Nx,Ny,length(Depth_Set)));
%%
uu=fx2D;
vv=fy2D;
k_Wavenum=k;
k_Medium=k_Wavenum*n_Medium;
figure
for i=1:Length_MN
pic_pos=i
v_s=Ini_NAx(pic_pos);
u_s=Ini_NAy(pic_pos);
G = real(1./(k_Medium*sqrt(1-lambda^2.*((uu-u_s).^2+(vv-v_s).^2))));
Gf = real(1./(k_Medium*sqrt(1-lambda^2.*((uu+u_s).^2+(vv+v_s).^2))));
Pupil = circshift(Aperture_fun,[Ini_PixelShiftx(pic_pos),Ini_PixelShifty(pic_pos)]);
Pupilf = circshift(Aperture_fun,-[Ini_PixelShiftx(pic_pos),Ini_PixelShifty(pic_pos)]);
uv_vector1=real(sqrt(1-lambda^2.*((uu-u_s).^2+(vv-v_s).^2)));
uv_vector2=real(sqrt(1-lambda^2.*((uu+u_s).^2+(vv+v_s).^2)));
uv_s=sqrt(1-lambda^2.*(u_s^2+v_s^2));
for j=1:length(Depth_Set)
PTF_3D(:,:,j)=...
(Pupil.*sin(k_Medium.*Depth_Set(j).*(uv_vector1 - uv_s)).*G+...
Pupilf.*sin(k_Medium.*Depth_Set(j).*(uv_vector2 - uv_s)).*Gf)+...
1i*(Pupil.*cos(k_Medium.*Depth_Set(j).*(uv_vector1 - uv_s)).*G-...
Pupilf.*cos(k_Medium.*Depth_Set(j).*(uv_vector2 - uv_s)).*Gf);
ATF_3D(:,:,j)=...
-(Pupil.*cos(k_Medium.*Depth_Set(j).*(uv_vector1 - uv_s)).*G+...
Pupilf.*cos(k_Medium.*Depth_Set(j).*(uv_vector2 - uv_s)).*Gf)+...
1i*(Pupil.*sin(k_Medium.*Depth_Set(j).*(uv_vector1 - uv_s)).*G-...
Pupilf.*sin(k_Medium.*Depth_Set(j).*(uv_vector2 - uv_s)).*Gf);
PTF_3D(:,:,j)=fftshift(PTF_3D(:,:,j));
ATF_3D(:,:,j)=fftshift(ATF_3D(:,:,j));
end
PTF_4D(:,:,:,pic_pos)=0.5*dz*k_Wavenum^2.*PTF_3D;
ATF_4D(:,:,:,pic_pos)=0.5*dz*k_Wavenum^2.*ATF_3D;
end
%% Calculate Eq.(7) and Eq.(8) in paper
sum_PTF = 0;
sum_ATF = 0;
conj_PTF_Iten=0;
conj_ATF_Iten=0;
conj_term1=0;
conj_term2=0;
tic
for i=1:Length_MN
pic_pos=i;
Itmp = I_Raw(:,:,pic_pos);
Ihat_tmp = fft2((Itmp));
sum_PTF=sum_PTF+abs(PTF_4D(:,:,:,pic_pos)).^2;
sum_ATF=sum_ATF+abs(ATF_4D(:,:,:,pic_pos)).^2;
conj_PTF_Iten=conj_PTF_Iten+conj(PTF_4D(:,:,:,pic_pos)).*repmat(Ihat_tmp,1,1,length(Depth_Set));
conj_ATF_Iten=conj_ATF_Iten+conj(ATF_4D(:,:,:,pic_pos)).*repmat(Ihat_tmp,1,1,length(Depth_Set));
conj_term1=conj_term1+conj(PTF_4D(:,:,:,pic_pos)).*ATF_4D(:,:,:,pic_pos);
conj_term2=conj_term2+conj(ATF_4D(:,:,:,pic_pos)).*PTF_4D(:,:,:,pic_pos);
end
%% Repeat IDT algorithm
Normalized_term=(sum_PTF+Alpha).*(sum_ATF+Beta)-conj_term1.*conj_term2;
V_re = ((sum_ATF+Beta).* conj_PTF_Iten - conj_term1.* conj_ATF_Iten) ./ Normalized_term;
V_im = ((sum_PTF+Alpha).* conj_ATF_Iten - conj_term2.* conj_PTF_Iten) ./ Normalized_term;
disp('Performing IDT spends...');
toc
v_im = real(ifft2((V_im)));
v_re = real(ifft2((V_re)));
n_re = sqrt(((n_Medium.^2 + v_re) + sqrt((n_Medium^2 + v_re).^2 + v_im.^2)) / 2);
n_im = v_im ./ n_re ./ 2;
RI=n_re+1i*n_im;