-
Notifications
You must be signed in to change notification settings - Fork 0
/
PACT_Recon.m
202 lines (191 loc) · 5.71 KB
/
PACT_Recon.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
%PACT_Recon
clear
clc
%%
% set experiment type and signal type
% exp_type: 1 -> num_data; 0 -> exp_data;
% sig_type: 1 -> velocity potential; 0 -> acoustic pressure
exp_type = 0;
sig_type = 1;
% data path
data_path = 'exp_data/19-06-10/3MHz/hair';
% data_path = 'exp_data/ustc';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% set sensor parameter
N = 128; % size of image [pixel]
Radius = floor(N * sqrt(2) / 2 + 2) - 1; % Radius [pixel]
sensor_radius = 25; % sensor radius [mm]
sensor_num = 128;
fs = 62.5; % sampling rate [MHz]
% theta range
theta_start = 0; % [deg]
range = 360; % [deg]
theta_end = range-range/sensor_num; % [deg]
theta = linspace(theta_start, theta_end, sensor_num); % angular distribution of sensors
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% signal processing
% data_type
% 1: structured data including SpeedOfSound, RFData and Index
% 0: non-structured data
data_type = 1;
fc = 8; % cut off frequency when filtering
delay = 0; % time delay
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% calculate differential matrix
order = 4;
tmp_img = ones(N);
tmp_sig = paradon(tmp_img, theta, Radius, 1);
[m, n] = size(tmp_sig);
clear tmp_img tmp_sig
D = diff_mat(m*n, 4);
%%
% load data
[pa_sig, neg_vp_sig] = signal_process(data_type, data_path, fs, fc, delay, sensor_radius, m, n);
if exp_type == 1
% simulation
I0=phantom(N);
% add noise
I0 = I0 + 0.03 * randn(N, N);
% velocity potential
P = paradon(I0, theta, Radius, 1);
% velocity potential -> acoustic pressure
if sig_type == 0
D_data = diff_mat(m, 4);
P = D_data * P;
end
P = P-min(min(P))+0.01;
elseif exp_type == 0
% experiment
if sig_type == 0
P = pa_sig;
elseif sig_type == 1
P = neg_vp_sig;
end
end
% P = P + 0.03 * randn(m, n);
% P(P<0) = 0;
p = reshape(P, m*n, 1);
%%
% load coefficient matrix
load('coef_mat\CoefMat_128_0_357.1875_128.mat');
if sig_type == 0
% if using acoustic pressure signal
A = D * A;
end
%%
%Reconstruction
% choosing reconstruction method
% case 1: ML_EM, case 2: ART, case 3: SART
method = 1;
switch method
case 1
% ML_EM
I = ones(N*N,1); %initialization
t = zeros(N*N,100);
SumA1 = sum(A);
fmat = moviein(100);
imshow(reshape(I, N, N))
fmat(1) = getframe;
for i = 1:100
t(:,i) = I;
p_ = A * I;
delta = p ./ p_;
delta(isnan(delta)) = 0;
delta(isinf(delta)) = 0;
I=I.*(sum(delta.*A)./SumA1)'; %normalization!!
I(isinf(I)) = 0;
% movie
if mod(i, 1) == 0
I_ = reshape(I,N,N);
I_ = full(I_);
imagesc(I_);
fmat(i+1) = getframe;
end
% end iteration till convergence
if norm(I-t(:,i))/norm(t(:,i)) < 5e-3
break
end
end
case 2
% ART
I = zeros(N*N, 1); %initialization
SumA2 = sum(A.^2, 2);
t = zeros(N*N, 100);
fmat = moviein(100);
for ii = 1:30
t(:, ii) = I;
for i = 1:m*n
p_ = A(i, :) * I;
delta = p(i) - p_;
C = delta .* A(i,:)' / SumA2(i);
C(isnan(C)) = 0;
I = I + C;
if mod(i, 100) == 0
I_ = reshape(I,N,N);
imagesc(I_);
fmat(i) = getframe;
end
end
end
case 3
% SART
I = ones(N*N, 1); %initialization
t = zeros(N*N, 100);
SumA2 = sum(A, 2);
fmat = moviein(100);
for ii = 1:30
t(:, ii) = I;
for i = 1:n
p_ = A((i-1)*m+1:i*m, :) * I;
delta = p((i-1)*m+1:i*m) - p_;
Dij = A((i-1)*m+1:i*m, :) .* delta ./ SumA2((i-1)*m+1:i*m);
Dij(isnan(Dij)) = 0;
D = sum(Dij);
C = (D./sum(A((i-1)*m+1:i*m, :)))';
C(isnan(C)) = 0;
C(isinf(C)) = 0;
I = I + C;
if mod(i,2) == 0
I_ = reshape(I,N,N);
imagesc(I_);
fmat(i) = getframe;
end
end
if norm(I-t(:,ii))/norm(t(:,ii)) < 1e-2
break
end
end
case 4
I = ones(N*N, 1);
t = zeros(N*N, 100);
alpha = 0.01;
SumA1 = sum(A)*10^17;
fmat = moviein(100);
for i = 1:100
t(:,i) = I;
res = sum(A*I-p);
I = I - alpha*res*SumA1';
if mod(i,2) == 0
I_ = reshape(I,N,N);
imagesc(I_);
fmat(i) = getframe;
end
end
end
%%
%========== O U T P U T ========
II=reshape(I,N,N);
II = full(II);
figure
imshow(II)
saveas(gcf, ['method_', num2str(method), '_', num2str(N)], 'tif')
%========== A N A L Y Z E =======
exp = repmat(p,1,size(t,2));
est = A*t;
r = sum((est-exp).^2);
figure
plot(r)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% save resuts
filename = ['results_', num2str(N), '_', num2str(theta_start), '_', num2str(theta_end), '_', num2str(sensor_num), '.mat'];
save(['.\result\', filename], 't');