-
Notifications
You must be signed in to change notification settings - Fork 2
/
GUI_seg.m
224 lines (170 loc) · 11.3 KB
/
GUI_seg.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
%% This function is written to calculate volume fraction.
% If chemical shift correction button is on, the volume fractions at each slice, row and column of all
% metabolites are calculated considering the chemical shift correction.
% If MRSI is acquired after T1w-MRI, CSF, WM and GM segmentation is used
% directly. However, if MRSI is acquired after T2w-MRI, all CSF, WM, and GM volumes, which are the segmentation volumes of T1w-MRI, are registered onto T2w-MRI.
% For more detail information of the registration onto T2w-MRI, please
% check T1registrationtoT2.m file.
%% This function creates conc, std, FWHM, SNR maps of the voxels.
% Author: Sevim Cengiz, Bogazici University, Turkey (2020-11-27)
% Contact: [email protected]
function [Pinfo, AlFWHM, AlSNR, AllNumStd, AllConc]=GUI_seg(UIFigure,Metabolites,Pinfo, chem_shift_ex, chem_shift_echo, chem_shift_echo2,ChemicalshiftcorrectionButtonGroup_SelectedObject_Text,MRSIacquiredafterButtonGroup_SelectedObject_Text,litoutpath,RFOV_dir,newmap,newmapname,newmapppm)
wait=uiprogressdlg(UIFigure,'Message','This process will take some time (~30 min).','Title','Segmentation');
numm=1;
T1segmentation(Pinfo);
switch newmap
case'Above-mentioned maps'
Metname={'Cr+PCr' 'Glu+Gln' 'GPC+PCh' 'Ins' 'Lac' 'Lip13a' 'Lip13b' 'Lip13a+Lip13b' 'NAA+NAAG'};
otherwise
Metname={'Cr+PCr' 'Glu+Gln' 'GPC+PCh' 'Ins' 'Lac' 'Lip13a' 'Lip13b' 'Lip13a+Lip13b' 'NAA+NAAG' newmapname};
end
name=[Pinfo.coordpath,Pinfo.sparname]; %% for LCModel output read and Concentration map generation
n=1;
counter=1;
%% Volume of Fraction Calculation
switch MRSIacquiredafterButtonGroup_SelectedObject_Text
%% mrsi acquired after t1w-mri
case 'T1w-MRI'
% CSF, WM, and GM volumes will be used for fraction calculation of each little voxels.
csf_path=[Pinfo.mainpath,'exam_1',filesep,'images',filesep,'T1',filesep,'nifti',filesep,Pinfo.name,'_Bet_pve_0.nii.gz'];
gm_path=[Pinfo.mainpath,'exam_1',filesep,'images',filesep,'T1',filesep,'nifti',filesep,Pinfo.name,'_Bet_pve_1.nii.gz'];
wm_path=[Pinfo.mainpath,'exam_1',filesep,'images',filesep,'T1',filesep,'nifti',filesep,Pinfo.name,'_Bet_pve_2.nii.gz'];
[csf_img]=ext_unzip(csf_path);
[gm_img]=ext_unzip(gm_path);
[wm_img]=ext_unzip(wm_path);
%Volume fraction calculation at each slice, row and column within the FOX box.
%for k=1:numel(Metabolites) % newly added
[sli row col]=size(Pinfo.littlevoxels);
maxcount=numel(Metabolites)*sli*row*col;
for isli=1:sli
for irow=1:row
for icol=1:col
counter=counter+1;
wait.Value=0.9/(((maxcount)/counter));
%Creating mask of each spectra voxel (little voxels)
locname=sprintf('sl%d_r%d_c%d',isli,irow,icol);
% littleFOVMask_file=[litoutpath,filesep,Pinfo.sparname,'_',locname,'_',Metabolites(k).name,'_FOV_mask.nii'];
littleFOVMask_file=[litoutpath,filesep,Pinfo.sparname,'_',locname,'_FOV_mask.nii'];
n=n+1;
% switch % newly added
% ChemicalshiftcorrectionButtonGroup_SelectedObject_Text
% case 'On'
% [Pinfo] = Mask_FOV_run_Pinfo_little(Pinfo,isli,irow,icol,k,littleFOVMask_file,chem_shift_ex(k).no,chem_shift_echo(k).no,chem_shift_echo2(k).no,RFOV_dir);
[Pinfo] = Mask_FOV_run_Pinfo_little(Pinfo,isli,irow,icol,numm,littleFOVMask_file,RFOV_dir);
% otherwise
% chem_shift_ex(k).no=0;
% chem_shift_echo(k).no=0;
%chem_shift_echo2(k).no=0;
%[Pinfo] = Mask_FOV_run_Pinfo_little(Pinfo,isli,irow,icol,k,littleFOVMask_file,chem_shift_ex(k).no,chem_shift_echo(k).no,chem_shift_echo2(k).no,RFOV_dir);
% end
[Pinfo]=VolFracCal(Pinfo,isli,irow,icol,numm,csf_img,gm_img,wm_img);
% tablename=sprintf('%s_sl%d_%d-%d.table', name, isli, irow, icol);
%
% if exist(tablename,'file')
% tableinfo=textread(tablename,'%s');
% [NumStd,Conc]=LCModelMap(tableinfo,newmap,newmapname,newmapppm);
% AllNumStd(:,isli,irow,icol)=NumStd;
% AllConc(:,isli,irow,icol)=Conc;
% [FWHM,SNR]=LCMout_info(tableinfo);
% AlFWHM(isli,irow,icol)=FWHM;
% AlSNR(isli,irow,icol)=SNR;
% else
% Conc=zeros(numel(Metname),1);
% NumStd=zeros(numel(Metname),1);
% NumStd(:,1)=999;
% AllNumStd(:,isli,irow,icol)=NumStd;
% AllConc(:,isli,irow,icol)=Conc;
% AlFWHM(isli,irow,icol)=str2num('2'); % If FWHM not found,number 2 is given to label FWHM for exclusion the voxel.
% AlSNR(isli,irow,icol)=str2num('0');% If SNR not found,number 0 is given to label SNR for exclusion the voxel.
%
% end
Pinfo.metab(numm).littlevoxels(isli,irow,icol).littlemask=[];
end
end
end
%% MRSI acquired after t2w-mri
otherwise % T2w-MRI
T1registrationtoT2(Pinfo);
% T1w-MRI and CSF,WM and GM volumes will be registered onto T2w-MRI
% because MRSI acquired after T2w-MRI.
csf_path=[Pinfo.mainpath,'exam_1',filesep,'images',filesep,'T1',filesep,'nifti',filesep,'Regist_T1_to_T2',filesep,Pinfo.name,'_Bet_pve_0_reg_T1_to_T2.nii.gz'];
gm_path=[Pinfo.mainpath,'exam_1',filesep,'images',filesep,'T1',filesep,'nifti',filesep,'Regist_T1_to_T2',filesep,Pinfo.name,'_Bet_pve_1_reg_T1_to_T2.nii.gz'];
wm_path=[Pinfo.mainpath,'exam_1',filesep,'images',filesep,'T1',filesep,'nifti',filesep,'Regist_T1_to_T2',filesep,Pinfo.name,'_Bet_pve_2_reg_T1_to_T2.nii.gz'];
[csf_img]=ext_unzip(csf_path);
[gm_img]=ext_unzip(gm_path);
[wm_img]=ext_unzip(wm_path);
% onto T2w-MRI registered CSF, WM and GM volumes will be used for fraction calculation.
%for k=1:numel(Metabolites)
[sli row col]=size(Pinfo.littlevoxels);
maxcount=numel(Metabolites)*sli*row*col;
for isli=1:sli
for irow=1:row
for icol=1:col
counter=counter+1;
wait.Value=0.9/(((maxcount)/counter));
%Creating mask of each spectra voxel (little voxels)
locname=sprintf('sl%d_r%d_c%d',isli,irow,icol);
littleFOVMask_file=[litoutpath,filesep,Pinfo.sparname,'_',locname,'_FOV_mask.nii'];
n=n+1;
% wait.Value=0.5*(n/(numel(Metabolites)*sli*row*col));
% switch ChemicalshiftcorrectionButtonGroup_SelectedObject_Text
% case 'On'
[Pinfo] = Mask_FOV_run_Pinfo_little(Pinfo,isli,irow,icol,1,littleFOVMask_file,RFOV_dir);
% otherwise
% chem_shift_ex(k).no=0;
% chem_shift_echo(k).no=0;
% chem_shift_echo2(k).no=0;
% [Pinfo] = Mask_FOV_run_Pinfo_little(Pinfo,isli,irow,icol,k,littleFOVMask_file,chem_shift_ex(k).no,chem_shift_echo(k).no,chem_shift_echo2(k).no,RFOV_dir);
%end
[Pinfo]=VolFracCal(Pinfo,isli,irow,icol,numm,csf_img,gm_img,wm_img);
% tablename=sprintf('%s_sl%d_%d-%d.table', name, isli, irow, icol);
%
% if exist(tablename,'file')
% tableinfo=textread(tablename,'%s');
% [NumStd,Conc]=LCModelMap(tableinfo,newmap,newmapname,newmapppm);
% AllNumStd(:,isli,irow,icol)=NumStd;
% AllConc(:,isli,irow,icol)=Conc;
% [FWHM,SNR]=LCMout_info(tableinfo);
% AlFWHM(isli,irow,icol)=FWHM;
% AlSNR(isli,irow,icol)=SNR;
% else
% Conc=zeros(numel(Metname),1);
% NumStd=zeros(numel(Metname),1);
% NumStd(:,1)=999;
% AllNumStd(:,isli,irow,icol)=NumStd;
% AllConc(:,isli,irow,icol)=Conc;
% AlFWHM(isli,irow,icol)=str2num('2'); % If FWHM not found,number 2 is given to label FWHM for exclusion the voxel.
% AlSNR(isli,irow,icol)=str2num('0');% If SNR not found,number 0 is given to label SNR for exclusion the voxel.
%
% end
Pinfo.metab(numm).littlevoxels(isli,irow,icol).littlemask=[];
end
end
end
end
%for k=1:numel(Metabolites)
for isli=1:sli
for irow=1:row
for icol=1:col
tablename=sprintf('%s_sl%d_%d-%d.table', name, isli, irow, icol);
if exist(tablename,'file')
tableinfo=textread(tablename,'%s');
[NumStd,Conc]=LCModelMap(tableinfo,newmap,newmapname,newmapppm);
AllNumStd(:,isli,irow,icol)=NumStd;
AllConc(:,isli,irow,icol)=Conc;
[FWHM,SNR]=LCMout_info(tableinfo);
AlFWHM(isli,irow,icol)=FWHM;
AlSNR(isli,irow,icol)=SNR;
else
Conc=zeros(numel(Metname),1);
NumStd=zeros(numel(Metname),1);
NumStd(:,1)=999;
AllNumStd(:,isli,irow,icol)=NumStd;
AllConc(:,isli,irow,icol)=Conc;
AlFWHM(isli,irow,icol)=str2num('2'); % If FWHM not found,number 2 is given to label FWHM for exclusion the voxel.
AlSNR(isli,irow,icol)=str2num('0');% If SNR not found,number 0 is given to label SNR for exclusion the voxel.
end
end
end
end
end