-
Notifications
You must be signed in to change notification settings - Fork 1
/
testScript.m
214 lines (152 loc) · 5.15 KB
/
testScript.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
dr = 0.25;
C = zeros(10,10);
for j = 1:1:10
for i = 1:1:j
C(i,j) = sqrt(((j+1))^2-(i)^2)-sqrt((j)^2-(i)^2);
end
end
C=C*2*dr;
C
break;
width = 2;
s = zeros(100,100);
sf = boxcar2(s,width);
size(sf)
phase_f = sf(2*width+1:end-(2*width+1),:);
size(phase_f)
break;
status = sprintf('Initializing... \n')
res = (3.85e-6);
lambda = 532e-9;
d =.50; % [m] Reconstruction distance
n_c = 2.312e27; % [m^-3] Critical plasma density
ref = 1;
hol_def_rgb = imread('../../data/Base_Shot_26.JPG');
hol_base_rgb = imread('../../data/Plasma_Shot_28.JPG');
rgb_red = 0.3;
rgb_green = 0.59;
rgb_blue = 0.11;
hol_def = double(hol_def_rgb(:,:,1).*rgb_red + hol_def_rgb(:,:,2).*rgb_green + hol_def_rgb(:,:,3).*rgb_blue)';
hol_base = double(hol_base_rgb(:,:,1).*rgb_red + hol_base_rgb(:,:,2).*rgb_green + hol_base_rgb(:,:,3).*rgb_blue)';
del_xi = res; % pixel size in x-direction
del_eta = res; % pixel size in y-direction
[phase_diff,x,y,xsize_fres,ysize_fres] = DHI_rec(hol_base,hol_def,d,res);
MS_Real = imag(phase_diff);
fidR = fopen("../../data/phaseDiffMatlab.dat",'w');
fwrite(fidR,MS_Real,'double');
fclose(fidR);
image(phase_diff);
break;
M = size(hol_def,2);
N = size(hol_def,1);
x_plt = -max(x)/2:x(2)-x(1):max(x)/2;
y_plt = -max(y)/2:y(2)-y(1):max(y)/2;
% Extracting the twin image:
% Labeling the matrix indices:
x_ind_vec = 1:1:M;
y_ind_vec = 1:1:N;
xmin=0;
xmax=0;
ymin=0;
ymax=0;
% Interpolating to match a spatial coordinate values to the
% nearest integer matrix indices:
x_min_ind = round(interp1(x,x_ind_vec,xmin));
x_max_ind = round(interp1(x,x_ind_vec,xmax));
y_min_ind = round(interp1(y,y_ind_vec,ymin));
y_max_ind = round(interp1(y,y_ind_vec,ymax));
% Defining the x,y spatial coordinate vectors for the extracted twin image:
x_twin = x(x_min_ind:x_max_ind);
x_twin = x_twin(1:10:end);
y_twin = y(y_min_ind:y_max_ind);
y_twin = y_twin(1:10:end);
twin_img = phase_diff(y_min_ind:y_max_ind,x_min_ind:x_max_ind);
twin_img = twin_img(1:10:end,1:10:end);
% Smoothing and unwrapping the twin image:
width = 8;
[unwrapped,phase_f,unsmoothed_unwrapped] = smooth_unwrap(twin_img,width);
break;
if (0)
status = sprintf('Computing Fresnel transform of def...')
b_def =fft2(hol_def.*chirp);
b_def =fftshift(b_def);
b_base =fft2(hol_base.*chirp);
b_base =fftshift(b_base);
phase_diff = angle(b_base.*conj(b_def));
fidR = fopen("../../data/holChirpRealMatlab.dat",'w');
fwrite(fidR,phase_diff,'double');
fclose(fidR);
break;
%MS_Real = real(chirp);
%MS_Imag = imag(chirp);
%fidR = fopen("../../data/chirpReal.dat",'w');
%fwrite(fidR,MS_Real,'double');
%fclose(fidR);
%fidI = fopen("../../data/chirpImag.dat",'w');
%fwrite(fidI,MS_Imag,'double');
%fclose(fidI);
status = sprintf('done with chirp. \n')
status = sprintf('Computing Fresnel transform of def...')
b_def =fft2(hol_def.*chirp);
b_def =fftshift(b_def);
%b_def = ifftshift(ifft2(fftshift(hol_def.*chirp)));
%status = sprintf('done with Fresnel transform of def. \n')
%status = sprintf('Computing Fresnel transform of base...')
b_base =fft2(hol_base.*chirp);
b_base =fftshift(b_base);
%b_base = ifftshift(ifft2(fftshift(hol_base.*chirp)));
fidBR = fopen("../../data/baseReal.dat",'w');
fwrite(fidBR,real(b_base),'double');
fclose(fidBR);
fidBI = fopen("../../data/baseImag.dat",'w');
fwrite(fidBI,imag(b_base),'double');
fclose(fidBI);
status = sprintf('done with Fresnel transform of base. \n')
status = sprintf('Computing interference phase...')
phase_diff = atan2(imag(b_base),real(b_base));
status = sprintf('done computing interference phase. \n')
fnt = 20;
xsize_fres = abs(d*lambda/M/res);
ysize_fres = abs(d*lambda/N/res);
x = 0:xsize_fres:(M-1)*xsize_fres;
y = 0:ysize_fres:(N-1)*ysize_fres;
x_plt = x - max(x)/2;
y_plt = y - max(y)/2;
figure(1); hold on;
fig1 = imagesc(x,y,phase_diff); axis image;%colormap gray;
set(gca,'Ydir','normal');
title('Reconstructed Phase [rad]','fontsize',fnt);
ylabel('\xi [m]','fontsize',fnt);
xlabel('\eta [m]','fontsize',fnt);
set(gca,'fontsize',fnt);
colorbar;
chirp = ones(N,M);
status = sprintf('Generating chirp...')
for n = 0:N-1
for m = 0:M-1
% Chirp function:
chirp(n+1,m+1) = exp((1i*pi/(d*lambda))*(((n-N/2)^2*...
del_eta^2)+((m-M/2)^2*del_xi^2)));
% Complex, constant phase factor:
% This factor is only required if we want a correctly scaled
% reconstructed intensity distribution. It is not needed in
% computing the interference phase distribution.
% A(n+1,m+1) = (exp(1i*k*d)/(1i*lambda*d))*...
% exp((1i*pi/(d*lambda))*(xfres(m+1)^2+yfres(n+1)^2));
end
end
L = size(hol_base);
M = L(2); % x-direction
N = L(1); % y-direction
param = 8;
x2 = linspace(-param*pi,param*pi,M+1); x = x2(1:M);
y2 = linspace(-param*pi,param*pi,N+1); y = y2(1:N);
for i = 1: length(hol_base(:,1))
hol_def(i,:) = hol_def(i,:).*(tanh(x+(param-1)*pi)-tanh(x-(param-1)*pi));
hol_base(i,:) = hol_base(i,:).*(tanh(x+(param-1)*pi)-tanh(x-(param-1)*pi));
end
for j = 1: length(hol_base(1,:))
hol_def(:,j) = hol_def(:,j).*(tanh(y+(param-1)*pi)-tanh(y-(param-1)*pi))';
hol_base(:,j) = hol_base(:,j).*(tanh(y+(param-1)*pi)-tanh(y-(param-1)*pi))';
end
end