-
Notifications
You must be signed in to change notification settings - Fork 0
/
ezshow_rsom_Quick.m
245 lines (223 loc) · 10.1 KB
/
ezshow_rsom_Quick.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
%%
% This is trial on wavelet-based denoising
% Yuanhui Huang
% 20180509
%%
% clear all; %close all;
% cd C:\Users\yuanhui\MATLAB\TAM;
cd C:\Users\Yuanhui\Matlab\TAM_hybrid;
% folder_name = 'C:\Users\yuanhui\MATLAB\TAM\Data\Data_Storage\';
folder_name = 'C:\Users\Yuanhui\Matlab\TAM_hybrid\Data\';
% fileParams.dataName = '201604211614_TAM_OLine25_Copper_5kV_US_100MHFM18_TAM_15-37.4us_AVG500_5';
% fileParams.dataName = '201604252007_TAM_OLine25_Yeast_tube3_surface_5kV_US_V3330_TAM_81-88us_AVG500_210';
fileParams.dataName = '201809221548_TAM50_OpenCPS_Nothing_YPofile_0-200us_AVG1024_3000';
% 201611282029_TAM_WNOilLine50_9ambornFishEgg_10kV_V3330_TAM_81-182us_AVG1024_320
% 201611282041_TAM_WNOilLine50_9ambornFishEgg_10kV_V3330_TAM_81-182us_AVG1024_300
% 201611282120_TAM_WNOilLine50_9ambornFishEgg_10kV_V3330_TAM_81-182us_AVG1024_280
% 201702042059_TAM_WNOil2Line50_32hourFishEgg_live-dead_10kV_V3330_TAM_81-182us_AVG1024_280
% 201702041945_TAM_WNOil2Line50_32hourFishEgg_dead-live_10kV_V3330_TAM_81-182us_AVG1024_260
% 201702071932_TAM_WNOil2Line50_4dayFishEgg_live-dead_TA_V3330_TAM_81-182us_AVG1024_270
% 201604211614_TAM_OLine25_Copper_5kV_US_100MHFM18_TAM_15-37.4us_AVG500_5
% 201604252007_TAM_OLine25_Yeast_tube3_surface_5kV_US_V3330_TAM_81-88us_AVG500_210
% 201608031645_TAM_WOilLine50_Fish_7kV_V3330_day1_TAM_81-182us_AVG1024_205
% 201608102201_TAM_WOilLine50_Fish_10kV_V3330_no_touching_day1_TAM_81-182us_AVG1024_210
% 201702112029_TAM_WNOil2Line50_8dayFish_10kV_V3330_TAM_81-182us_AVG1024_260
fileParams.data = [folder_name '\'];
isDirExist([fileParams.data fileParams.dataName], 1); % 1: mkdir(FullPath);
load([fileParams.data fileParams.dataName '.mat']);
is_rsom = 0;
Fs = 500e6;
dt = 1/Fs;
SoS = 1.498; % speed of sound 1.5mm/us
% SoS = 0.970; % speed of sound 1.5mm/us
% tDelay = 25e-6;
tDelay=trigDelay*1/Fs;
tt_ = (tDelay+dt):dt:(tDelay+dt*size(S,2));
% dz = 0.05;
% Lz = (size(S,1)-1).*dz;
% ZZ_ = [0:dz:Lz];
X = int16((xLim(2)-xLim(1))/dx+1);
Y = int16((yLim(2)-yLim(1))/dy+1);
%% Extracting region of interest
% Slice_T1 = 9.8e-6; Window = 11.5e-6;
% Slice_T1 = 19.6e-6; Window = 4e-6;
% % Slice_T1 = 20e-6; Window = 23e-6;
% Slice_T1 = (8.8e-6).*1; Slice_T2 = (9.2e-6).*1;
Slice_T1 = (8.*1e-6).*1;
Slice_T2 = (9.*1e-6).*1;
% Slice_T1 = ((12.50)./SoS.*1e-6).*1;
% Slice_T2 = ((14.5)./SoS.*1e-6).*1;
Window = Slice_T2 - Slice_T1;
is_Tiff=0;
% Slice_T1 = 16.2e-6; Window = 2e-6;
% Slice_T1 = 1.5e-6; Window = 0.5e-6;
% Slice_T1 = 3.0e-6; Window = 1e-6;
% Slice_T1 = 10e-6; Window = 2e-6; % Oil2Line
% Slice_T1 = 20e-6; Window = 4e-6; % Oil2Line
MIP_XYZ = 0; % Slice 0. for all, 1. XZ, 2. YZ, 3. XY
% Slice_T1_End=11.8e-6; Slice_T1_Start=9.8e-6;
% Slice_T2_Start=19.6e-6; Slice_T2_End=23.6e-6;
% Slice_T2_Start=19e-6; Slice_T2_End=23e-6;
Slice_T1_Start=trigDelay.*2e-9; Slice_T1_End=9e-6; % WOiLine
Slice_T2_Start=14e-6; Slice_T2_End=size(S,2)*2e-9+trigDelay.*2e-9;
% Slice_T1_End=12e-6; Slice_T1_Start=10e-6; % Oil2Line
% Slice_T2_Start=20e-6; Slice_T2_End=24e-6;
% Slice_T1_End=2e-6; Slice_T1_Start=1.5e-6; % 100MHz
% Slice_T2_Start=3e-6; Slice_T2_End=4e-6;
if is_rsom==1
if Slice_T2 <= Slice_T1_End
IS_TA = 1;
SS = double(S(:,((tt_>=Slice_T1_Start)&(tt_<=Slice_T1_End)))).* InputRange ./ 2^15; % mV
tt_ = tt_((tt_>=Slice_T1_Start)&(tt_<=Slice_T1_End));
elseif Slice_T1 >= Slice_T2_Start
IS_TA = 0;
SS = double(S(:,((tt_>=Slice_T2_Start)&(tt_<=Slice_T2_End)))).* InputRange ./ 2^15; % mV
tt_ = tt_((tt_>=Slice_T2_Start)&(tt_<=Slice_T2_End));
tDelay=trigDelay*1/Fs;
end
SS=double(reshape(SS,X,Y,size(SS,2)));
SS = SS(1:2:end,1:2:end,:);
[X Y] = size(SS);
SS=reshape(SS,X*Y,size(SS,3));
dx=dx*2;
elseif is_rsom==0
if Slice_T2 <= Slice_T1_End
IS_TA = 1;
SS = double(S(:,((tt_>=Slice_T1_Start)&(tt_<=Slice_T1_End)))).* 1000; % mV
tt_ = tt_((tt_>=Slice_T1_Start)&(tt_<=Slice_T1_End));
elseif Slice_T1 >= Slice_T2_Start
IS_TA = 0;
SS = double(S(:,((tt_>=Slice_T2_Start)&(tt_<=Slice_T2_End)))).* 1000; % mV
tt_ = tt_((tt_>=Slice_T2_Start)&(tt_<=Slice_T2_End));
tDelay = tDelay*2;
end
% SS = double(S) .* 1000; % mV
end
%
Delta_tt_ = max(tt_)-min(tt_);
tic
% %% Denoising
% for i=1:size(SS,1)
% % SS(i,:) = denoising(SS(i,:),0.618, round(log2(length(tt_)).*0.382));
% % SS(i,:) = denoising(SS(i,:),max(SS(:)).*0.05, floor(log2(length(tt_)).*1));
% SS(i,:) = denoising(SS(i,:),max(SS(:))./50, 12);
% % [SS(i,:), E, status] = tvdip(SS(i,:),tvdiplmax(SS(i,:))*5e-3,0,1e-3,100);
% end
%
% % Bandpass
SS = filtS(SS,dt,min(dx, dy),2);
% SS=double(reshape(SS,X,Y,size(SS,2)));
% toc
%% SAFT recon
if ~IS_TA % title('US B scan');
Window=Window/2;
Delta_tt_ = Delta_tt_/2;
tDelay = tDelay/2;
ind = [1:1:size(SS,2)]';
SS = (sparse(ceil(ind/2),ind,1)*SS')'; % downsampling the US sequence to be alike TA sequence
end
% Add path
addpath('C:\Users\yuanhui\MATLAB\TAM\SAFT_recon');
addpath('C:\Users\yuanhui\MATLAB\TAM\SAFT_recon\FieldII\Field_II_PC7');
addpath('C:\Users\yuanhui\MATLAB\TAM\SAFT_recon\FieldII\usefullFunctions');
addpath('C:\Users\yuanhui\MATLAB\TAM\SAFT_recon\FieldII');
% Load parameters:
myReconSetup;
% myReconSetup100MHz;
% File name:
% folder_name = 'C:\Users\Chucheng\Documents\MATLAB\TAM\DATA4T';
% fileParams.data = [folder_name, '\'];
% fileParams.dataName = '201702071932_TAM_WNOil2Line50_4dayFishEgg_live-dead_TA_V3330_TAM_81-182us_AVG1024_270';
fileParams.recon = [fileParams.data fileParams.dataName '\'];
fileParams.main = [fileParams.data fileParams.dataName '\'];
fileParams.dataFolder = '';
isDirExist(fileParams.recon);
% Look for the files to reconstruct inside the measurement folder:
files = dir([fileParams.data fileParams.dataName '.mat']);
nFiles = length(files);
fprintf('There are %i files to reconstruct!\n',nFiles);
pause(0.1);
% Choose which frequency band to reconstruct
RAW_flag = 1;
AF_flag = 0;
LF_flag = 0;
HF_flag = 0;
for ii = 1:nFiles
%=====Choose the right file:
fprintf('%i....',ii);
reconParams = det50.reconParams;
transducerParams = det50.transducerParams;
%=====All frequencies: without SAFT
if RAW_flag
fileParams.reconExt = 'RAW';% File Extension
reconParams.f_BP = [0 Fs];
% R=medfilt3(double(reshape(SS,X,Y,size(SS,2))));
R = double(reshape(SS,X,Y,size(SS,2)));
[X, Y, Z] = size(R);
nGrid = max([X Y (X-1)*dx*1e3/reconParams.GRID_DS+1 (Y-1)*dy*1e3/reconParams.GRID_DS+1]);
R = imresize(R,[(X-1)*dx*1e3/reconParams.GRID_DS+1 (Y-1)*dy*1e3/reconParams.GRID_DS+1],'bicubic');
[X, Y, Z] = size(R);
% R = imresize(abs(hilbert(imresize(R,[X*Y Z]))),[X Y Z]);
dt = Delta_tt_ ./ Z; tt_ = tDelay + [0:Z-1].*dt;
% R((R>=0.2.*max(R(:)))) = 0;
% R((R<=0.2.*min(R(:)))) = 0;
% show_data_Quick;
[tt_ROI ROI] = show_data_Quick(tt_, R, Slice_T1, Slice_T2, MIP_XYZ, yLim, xLim, SoS, IS_TA, dt, dx, dy, dz, reconParams);
if is_Tiff==1
% ROI((ROI>=0.2.*max(ROI(:)))) = 0;
myTiff(ROI,fileParams,IS_TA);
end % % Save Tiff
end
%=====All frequencies:
if AF_flag
fileParams.reconExt = 'AF';% File Extension
reconParams.f_BP = reconParams.f_BPA;
% Now reconstruct:
% Recon3Dnew_mo(fileParams, reconParams, transducerParams);
R = double(myRecon3Dnew(SS, fileParams, reconParams, transducerParams));
R = -medfilt3(double(R)); % SAFT reverse the phase
tt_ = Slice_T1+[1:size(R,3)].*Window./size(R,3);
[X, Y, Z] = size(R);
% nGrid = max([X Y (X-1)*min([dx dy dz])*1e3/reconParams.GRID_DS+1 (Y-1)*min([dx dy dz])*1e3/reconParams.GRID_DS+1]);
% R = imresize(R,[(X-1)*dx*1e3/reconParams.GRID_DS+1 (Y-1)*dy*1e3/reconParams.GRID_DS+1],'bicubic');
% [X Y Z] = size(R);
dt = Delta_tt_ ./ Z; tt_ = tDelay + [0:Z-1].*dt;
% show_data_Quick;
[tt_ROI ROI] = show_data_Quick(tt_, tt_ROI, R, Slice_T1, Slice_T2, MIP_XYZ, yLim, xLim, SoS, IS_TA);
if is_Tiff==1 myTiff(ROI,fileParams,IS_TA); end % % Save Tiff
end
%=====Low frequencies:
if LF_flag
fileParams.reconExt = 'LF';% File Extension
reconParams.f_BP = reconParams.f_BPL;
% Now reconstruct:
R = double(myRecon3Dnew(SS, fileParams, reconParams, transducerParams));
R = -medfilt3(double(R)); % SAFT reverse the phase
[X, Y, Z] = size(R);
% nGrid = max([X Y (X-1)*min([dx dy dz])*1e3/reconParams.GRID_DS+1 (Y-1)*min([dx dy dz])*1e3/reconParams.GRID_DS+1]);
% R = imresize(R,[(X-1)*dx*1e3/reconParams.GRID_DS+1 (Y-1)*dy*1e3/reconParams.GRID_DS+1],'bicubic');
% [X Y Z] = size(R);
dt = Delta_tt_ ./ Z; tt_ = tDelay + [0:Z-1].*dt;
% show_data_Quick;
[tt_ROI ROI] = show_data_Quick(tt_, tt_ROI, R, Slice_T1, Slice_T2, MIP_XYZ, yLim, xLim, SoS, IS_TA);
if is_Tiff==1 myTiff(ROI,fileParams,IS_TA); end % % Save Tiff
end
%=====High frequencies:
if HF_flag
fileParams.reconExt = 'HF';% File Extension
reconParams.f_BP = reconParams.f_BPH;
% Now reconstruct:
R = double(myRecon3Dnew(SS, fileParams, reconParams, transducerParams));
R = medfilt3(double(R)); % SAFT reverse the phase
[X, Y, Z] = size(R);
% nGrid = max([X Y (X-1)*min([dx dy dz])*1e3/reconParams.GRID_DS+1 (Y-1)*min([dx dy dz])*1e3/reconParams.GRID_DS+1]);
% R = imresize(R,[(X-1)*dx*1e3/reconParams.GRID_DS+1 (Y-1)*dy*1e3/reconParams.GRID_DS+1],'bicubic');
% [X Y Z] = size(R);
dt = Delta_tt_ ./ Z; tt_ = tDelay + [0:Z-1].*dt;
% show_data_Quick;
[tt_ROI ROI] = show_data_Quick(tt_, tt_ROI, R, Slice_T1, Slice_T2, MIP_XYZ, yLim, xLim, SoS, IS_TA);
if is_Tiff==1 myTiff(ROI,fileParams,IS_TA); end % % Save Tiff
end
% close all;
end
% ROI=medfilt3(double(reshape(ROI,X,Y,size(ROI,2))));