Skip to content

Commit 522fabb

Browse files
committed
Update export_fig to v3.15; some cosmetic changes
1 parent cd83a43 commit 522fabb

File tree

11 files changed

+84
-77
lines changed

11 files changed

+84
-77
lines changed

CoRegStandAlone/CoReg.m

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
% Coregistration of MRS voxel volumes to imaging datasets, based on headers.
44

5-
MRS_struct.version.coreg = '201204';
5+
MRS_struct.version.coreg = '210701';
66

77
warning('off'); % temporarily suppress warning messages
88

99
% First check if SPM12 is installed and on the search path
10-
spmversion = fileparts(which('spm'));
11-
if isempty(spmversion)
10+
spm_version = fileparts(which('spm'));
11+
if isempty(spm_version)
1212
msg = 'SPM not found! Please install SPM12 and make sure it is in your search path.';
1313
msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg);
1414
error(msg);
15-
elseif strcmpi(spmversion(end-3:end),'spm8')
15+
elseif strcmpi(spm_version(end-3:end),'spm8')
1616
msg = ['SPM8 detected. Gannet no longer supports SPM8. ' ...
1717
'Please install SPM12 and make sure it is in your search path.'];
1818
msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg);
1919
error(msg);
2020
end
2121

2222
if MRS_struct.ii ~= length(struc)
23-
error('The number of nifti files does not match the number of MRS files processed by CoRegStandAlone.');
23+
error('The number of NIfTI files does not match the number of MRS files processed by CoRegStandAlone.');
2424
end
2525

2626
numscans = numel(MRS_struct.metabfile);
@@ -151,9 +151,7 @@
151151
colormap('gray');
152152
img = MRS_struct.mask.(vox{kk}).img{ii}(:);
153153
caxis([0 mean(img(img > 0.01)) + 3*std(img(img > 0.01))]);
154-
axis equal;
155-
axis tight;
156-
axis off;
154+
axis equal tight off;
157155
text(10, size(MRS_struct.mask.(vox{kk}).img{ii},1)/2, 'L', 'Color', [1 1 1], 'FontSize', 20);
158156
text(size(MRS_struct.mask.(vox{kk}).img{ii},2) - 20, size(MRS_struct.mask.(vox{kk}).img{ii},1)/2, 'R', 'Color', [1 1 1], 'FontSize', 20);
159157
set(ha,'pos',[0 0.15 1 1]);
@@ -165,15 +163,13 @@
165163
axes('Position', [0.825, 0.05, 0.125, 0.125]);
166164
imshow(I);
167165
text(0.9, 0, MRS_struct.version.Gannet, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 14, 'FontWeight', 'bold', 'HorizontalAlignment', 'left');
168-
axis off;
169-
axis square;
166+
axis off square;
170167

171168
% Gannet documentation
172169
axes('Position', [(1-0.9)/2, 0.025, 0.9, 0.15]);
173170
str = 'For complete documentation, please visit: https://markmikkelsen.github.io/Gannet-docs';
174171
text(0.5, 0, str, 'FontName', 'Arial', 'FontSize', 11, 'HorizontalAlignment', 'center');
175-
axis off;
176-
axis square;
172+
axis off square;
177173

178174
% For Philips .data
179175
if strcmpi(MRS_struct.p.vendor,'Philips_data')
@@ -207,7 +203,6 @@
207203
end
208204
saveas(gcf, pdfname);
209205

210-
211206
end
212207

213208
end

CoRegStandAlone/CoRegStandAlone.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4444

4545
MRS_struct.version.Gannet = '3.2.0';
46-
MRS_struct.version.load = '210624';
46+
MRS_struct.version.load = '210730';
4747
MRS_struct.ii = 0;
4848
if size(metabfile,2) == 1
4949
metabfile = metabfile';

CoRegStandAlone/Seg.m

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@
1111
% This is useful if only the tissue segmentation information is supposed to
1212
% be obtained.
1313

14-
MRS_struct.version.segment = '201204';
14+
MRS_struct.version.segment = '210331';
1515
vox = MRS_struct.p.vox(1);
1616

1717
warning('off'); % temporarily suppress warning messages
1818

1919
% First check if SPM12 is installed and on the search path
20-
spmversion = fileparts(which('spm'));
21-
if isempty(spmversion)
20+
spm_version = fileparts(which('spm'));
21+
if isempty(spm_version)
2222
msg = 'SPM not found! Please install SPM12 and make sure it is in your search path.';
2323
msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg);
2424
error(msg);
25-
elseif strcmpi(spmversion(end-3:end),'spm8')
25+
elseif strcmpi(spm_version(end-3:end),'spm8')
2626
msg = ['SPM8 detected. Gannet no longer supports SPM8. ' ...
2727
'Please install SPM12 and make sure it is in your search path.'];
2828
msg = hyperlink('https://www.fil.ion.ucl.ac.uk/spm/software/spm12', 'SPM12', msg);
2929
error(msg);
3030
end
3131

3232
kk = 1;
33-
setupSPM = 1;
33+
setup_spm = 1;
3434

3535
for ii = 1:length(MRS_struct.metabfile)
3636

37-
% 1 - Take nifti from GannetCoRegister and segment it in SPM
37+
% 1. Take NIfTI from GannetCoRegister and segment it in SPM
3838

3939
[T1dir, T1name, T1ext] = fileparts(MRS_struct.mask.(vox{kk}).T1image{ii});
4040
struc = MRS_struct.mask.(vox{kk}).T1image{ii};
@@ -49,16 +49,16 @@
4949
filesExist(jj) = exist(tmp{jj}, 'file'); %#ok<AGROW>
5050
end
5151
if ~all(filesExist)
52-
if setupSPM
53-
% Set up SPM for batch processing (do it once and only when needed)
52+
if setup_spm
53+
% Set up SPM for batch processing (do it once per batch)
5454
spm('defaults','fmri');
5555
spm_jobman('initcfg');
56-
setupSPM = 0;
56+
setup_spm = 0;
5757
end
5858
CallSPM12segmentation(struc);
5959
end
6060

61-
% 2 - Determine GM, WM and CSF fractions for each voxel
61+
% 2. Calculate QC metrics and GM, WM, and CSF fractions for each voxel
6262

6363
if strcmp(T1dir,'')
6464
T1dir = '.';
@@ -73,40 +73,40 @@
7373
WMvol = spm_vol(WM);
7474
CSFvol = spm_vol(CSF);
7575
airvol = spm_vol(air);
76-
76+
7777
% Segmentation quality metrics (Chua et al. JMRI, 2009; Ganzetti et
7878
% al. Front. Neuroinform., 2016; Esteban et al. PLOS One, 2017)
7979
T1 = spm_vol(struc);
8080
T1_tmp = T1.private.dat(:,:,:);
81-
81+
8282
WMvol_tmp = WMvol.private.dat(:,:,:);
8383
WMvol_tmp(WMvol_tmp < 0.9) = NaN;
8484
WMvol_thresh = WMvol_tmp .* T1_tmp;
8585
WMvol_thresh = WMvol_thresh(:);
86-
86+
8787
GMvol_tmp = GMvol.private.dat(:,:,:);
8888
GMvol_tmp(GMvol_tmp < 0.9) = NaN;
8989
GMvol_thresh = GMvol_tmp .* T1_tmp;
9090
GMvol_thresh = GMvol_thresh(:);
91-
91+
9292
airvol_tmp = airvol.private.dat(:,:,:);
9393
airvol_tmp(airvol_tmp < 0.9) = NaN;
9494
airvol_thresh = airvol_tmp .* T1_tmp;
9595
airvol_thresh = airvol_thresh(:);
96-
97-
MRS_struct.out.tissue.CV_WM(ii) = std(WMvol_thresh,'omitnan') / mean(WMvol_thresh,'omitnan');
98-
MRS_struct.out.tissue.CV_GM(ii) = std(GMvol_thresh,'omitnan') / mean(GMvol_thresh,'omitnan');
99-
MRS_struct.out.tissue.CJV(ii) = (std(WMvol_thresh,'omitnan') + std(GMvol_thresh,'omitnan')) ...
100-
/ abs(mean(WMvol_thresh,'omitnan') - mean(GMvol_thresh,'omitnan'));
101-
MRS_struct.out.tissue.CNR(ii) = abs(mean(WMvol_thresh,'omitnan') - mean(GMvol_thresh,'omitnan')) / ...
102-
sqrt(var(airvol_thresh,'omitnan') + var(WMvol_thresh,'omitnan') + var(GMvol_thresh,'omitnan'));
96+
97+
MRS_struct.out.tissue.CV_WM(ii) = std(WMvol_thresh, 'omitnan') / mean(WMvol_thresh, 'omitnan');
98+
MRS_struct.out.tissue.CV_GM(ii) = std(GMvol_thresh, 'omitnan') / mean(GMvol_thresh, 'omitnan');
99+
MRS_struct.out.tissue.CJV(ii) = (std(WMvol_thresh, 'omitnan') + std(GMvol_thresh, 'omitnan')) ...
100+
/ abs(mean(WMvol_thresh, 'omitnan') - mean(GMvol_thresh, 'omitnan'));
101+
MRS_struct.out.tissue.CNR(ii) = abs(mean(WMvol_thresh, 'omitnan') - mean(GMvol_thresh, 'omitnan')) / ...
102+
sqrt(var(airvol_thresh, 'omitnan') + var(WMvol_thresh, 'omitnan') + var(GMvol_thresh, 'omitnan'));
103103

104104
T1_tmp = T1_tmp(:);
105105
n_vox = numel(T1_tmp);
106106
efc_max = n_vox * (1/sqrt(n_vox)) * log(1/sqrt(n_vox));
107107
b_max = sqrt(sum(T1_tmp.^2));
108108
MRS_struct.out.tissue.EFC(ii) = (1/efc_max) .* sum((T1_tmp ./ b_max) .* log((T1_tmp + eps) ./ b_max));
109-
109+
110110
% Loop over voxels if PRIAM
111111
for kk = 1:length(vox)
112112

@@ -115,7 +115,7 @@
115115

116116
% GM
117117
O_GMvox.fname = fullfile(a, [b '_GM' c]);
118-
O_GMvox.descrip = 'GMmasked_MRS_Voxel_Mask';
118+
O_GMvox.descrip = 'MRS_voxel_mask_GM';
119119
O_GMvox.dim = voxmaskvol.dim;
120120
O_GMvox.dt = voxmaskvol.dt;
121121
O_GMvox.mat = voxmaskvol.mat;
@@ -124,7 +124,7 @@
124124

125125
% WM
126126
O_WMvox.fname = fullfile(a, [b '_WM' c]);
127-
O_WMvox.descrip = 'WMmasked_MRS_Voxel_Mask';
127+
O_WMvox.descrip = 'MRS_voxel_mask_WM';
128128
O_WMvox.dim = voxmaskvol.dim;
129129
O_WMvox.dt = voxmaskvol.dt;
130130
O_WMvox.mat = voxmaskvol.mat;
@@ -133,14 +133,14 @@
133133

134134
% CSF
135135
O_CSFvox.fname = fullfile(a, [b '_CSF' c]);
136-
O_CSFvox.descrip = 'CSFmasked_MRS_Voxel_Mask';
136+
O_CSFvox.descrip = 'MRS_voxel_mask_CSF';
137137
O_CSFvox.dim = voxmaskvol.dim;
138138
O_CSFvox.dt = voxmaskvol.dt;
139139
O_CSFvox.mat = voxmaskvol.mat;
140140
CSF_voxmask_vol = CSFvol.private.dat(:,:,:) .* voxmaskvol.private.dat(:,:,:);
141141
O_CSFvox = spm_write_vol(O_CSFvox, CSF_voxmask_vol);
142142

143-
% 3 - Calculate a CSF-corrected i.u. value and output it to the structure
143+
% 3. Calculate a CSF-corrected i.u. value and output it to the structure
144144

145145
GMsum = sum(sum(sum(O_GMvox.private.dat(:,:,:))));
146146
WMsum = sum(sum(sum(O_WMvox.private.dat(:,:,:))));
@@ -154,7 +154,7 @@
154154
MRS_struct.out.(vox{kk}).tissue.fWM(ii) = fWM;
155155
MRS_struct.out.(vox{kk}).tissue.fCSF(ii) = fCSF;
156156

157-
% 4 - Build output
157+
% 4. Build output
158158

159159
if ishandle(104)
160160
clf(104);
@@ -296,8 +296,6 @@
296296

297297
warning('on'); % turn warnings back on
298298

299-
end
300-
301299

302300
function img_montage = PlotSegmentedVoxels(struc, voxoff, voxmaskvol, O_GMvox, O_WMvox, O_CSFvox)
303301

@@ -368,16 +366,12 @@
368366

369367
ha = subplot(2,3,1:3);
370368
imagesc(img_montage);
371-
axis equal;
372-
axis tight;
373-
axis off;
369+
axis equal tight off;
374370
text(floor(size(mask_t,2)/2), 20, 'Voxel', 'Color', [1 1 1], 'FontSize', 20, 'HorizontalAlignment', 'center');
375371
text(floor(size(mask_t,2)) + floor(size(mask_t,2)/2), 20, 'GM', 'Color', [1 1 1], 'FontSize', 20, 'HorizontalAlignment', 'center');
376372
text(2*floor(size(mask_t,2)) + floor(size(mask_t,2)/2), 20, 'WM', 'Color', [1 1 1], 'FontSize', 20, 'HorizontalAlignment', 'center');
377373
text(3*floor(size(mask_t,2)) + floor(size(mask_t,2)/2), 20, 'CSF', 'Color', [1 1 1], 'FontSize', 20, 'HorizontalAlignment', 'center');
378-
set(ha,'pos',[0 0.17 1 1]);
379-
380-
end
374+
set(ha, 'pos', [0 0.17 1 1]);
381375

382376

383377

GannetCoRegister.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
end
2727

2828
if MRS_struct.ii ~= length(struc)
29-
error('The number of nifti files does not match the number of MRS files processed by GannetLoad.');
29+
error('The number of NIfTI files does not match the number of MRS files processed by GannetLoad.');
3030
end
3131

3232
run_count = 0;

GannetMask_Philips.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
lr_ang = MRS_struct.p.voxang(ii,1);
5959
cc_ang = MRS_struct.p.voxang(ii,3);
6060

61-
% We need to flip ap and lr axes to match NIFTI convention
61+
% We need to flip ap and lr axes to match NIfTI convention
6262
ap_off = -ap_off;
6363
lr_off = -lr_off;
6464
ap_ang = -ap_ang;

GannetMask_SiemensRDA.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
ii = 1;
2222
end
2323

24-
% Parse RDA filename and establish nifti voxelmask filename
24+
% Parse RDA filename and establish NIfTI voxelmask filename
2525
[path, name] = fileparts(fname);
2626
fidoutmask = fullfile(path,[name '_mask.nii']);
2727
fid = fopen(fname);
@@ -168,7 +168,7 @@
168168
halfpixshift(3) = -halfpixshift(3);
169169
XYZ = XYZ + repmat(halfpixshift, [1 size(XYZ,2)]);
170170

171-
% We need to flip ap and lr axes to match NIFTI convention
171+
% We need to flip ap and lr axes to match NIfTI convention
172172
VoxOffs(1) = -VoxOffs(1);
173173
VoxOffs(2) = -VoxOffs(2);
174174

GannetMask_SiemensTWIX.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
halfpixshift(3) = -halfpixshift(3);
123123
XYZ = XYZ + repmat(halfpixshift, [1 size(XYZ,2)]);
124124

125-
% We need to flip ap and lr axes to match NIFTI convention
125+
% We need to flip ap and lr axes to match NIfTI convention
126126
VoxOffs(1) = -VoxOffs(1);
127127
VoxOffs(2) = -VoxOffs(2);
128128

GannetSegment.m

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
for ii = 1:MRS_struct.p.numScans
4040

41-
% 1. Take nifti from GannetCoRegister and segment it in SPM
41+
% 1. Take NIfTI from GannetCoRegister and segment it in SPM
4242

4343
[T1dir, T1name, T1ext] = fileparts(MRS_struct.mask.(vox{kk}).T1image{ii});
4444
struc = MRS_struct.mask.(vox{kk}).T1image{ii};
@@ -211,19 +211,19 @@
211211
text_pos = 1;
212212

213213
if strcmp(MRS_struct.p.vendor,'Siemens_rda')
214-
[~,filesExist,tmp3] = fileparts(MRS_struct.metabfile{1,ii*2-1});
214+
[~,tmp2,tmp3] = fileparts(MRS_struct.metabfile{1,ii*2-1});
215215
else
216-
[~,filesExist,tmp3] = fileparts(MRS_struct.metabfile{1,ii});
216+
[~,tmp2,tmp3] = fileparts(MRS_struct.metabfile{1,ii});
217217
end
218-
fname = [filesExist tmp3];
218+
fname = [tmp2 tmp3];
219219
if length(fname) > 30
220220
fname = [fname(1:12) '...' fname(end-11:end)];
221221
end
222222
text(0.5, text_pos-0.12, 'Filename: ', 'FontName', 'Arial', 'HorizontalAlignment','right', 'VerticalAlignment', 'top', 'FontSize', 13);
223223
text(0.5, text_pos-0.12, [' ' fname], 'FontName', 'Arial', 'VerticalAlignment', 'top', 'FontSize', 13, 'Interpreter', 'none');
224224

225-
[~,filesExist,tmp3] = fileparts(MRS_struct.mask.(vox{kk}).T1image{ii});
226-
T1image = [filesExist tmp3];
225+
[~,tmp2,tmp3] = fileparts(MRS_struct.mask.(vox{kk}).T1image{ii});
226+
T1image = [tmp2 tmp3];
227227
if length(T1image) > 30
228228
T1image = [T1image(1:12) '...' T1image(end-11:end)];
229229
end
@@ -247,16 +247,16 @@
247247
switch target{jj}
248248
case 'GABA'
249249
tmp1 = 'GABA+/Water (CSF-corrected): ';
250-
filesExist = sprintf(' %.2f i.u.', MRS_struct.out.(vox{kk}).GABA.ConcIU_CSFcorr(ii));
250+
tmp2 = sprintf(' %.2f i.u.', MRS_struct.out.(vox{kk}).GABA.ConcIU_CSFcorr(ii));
251251
case 'Lac'
252252
tmp1 = 'Lac+MM/Water (CSF-corrected): ';
253-
filesExist = sprintf(' %.2f i.u.', MRS_struct.out.(vox{kk}).Lac.ConcIU_CSFcorr(ii));
253+
tmp2 = sprintf(' %.2f i.u.', MRS_struct.out.(vox{kk}).Lac.ConcIU_CSFcorr(ii));
254254
case {'Glx','GSH','EtOH'}
255255
tmp1 = [target{jj} '/Water (CSF-corrected): '];
256-
filesExist = sprintf(' %.2f i.u.', MRS_struct.out.(vox{kk}).(target{jj}).ConcIU_CSFcorr(ii));
256+
tmp2 = sprintf(' %.2f i.u.', MRS_struct.out.(vox{kk}).(target{jj}).ConcIU_CSFcorr(ii));
257257
end
258258
text(0.5, text_pos, tmp1, 'FontName', 'Arial', 'HorizontalAlignment','right', 'VerticalAlignment', 'top', 'FontSize', 13);
259-
text(0.5, text_pos, filesExist, 'FontName', 'Arial', 'VerticalAlignment', 'top', 'FontSize', 13);
259+
text(0.5, text_pos, tmp2, 'FontName', 'Arial', 'VerticalAlignment', 'top', 'FontSize', 13);
260260
end
261261
end
262262

@@ -286,11 +286,11 @@
286286
MRS_struct.mask.(vox{kk}).img_montage{ii} = PlotSegmentedVoxels(struc, voxoff, voxmaskvol, O_GMvox, O_WMvox, O_CSFvox);
287287

288288
if strcmp(MRS_struct.p.vendor, 'Siemens_rda')
289-
[~,tmp,filesExist] = fileparts(MRS_struct.metabfile{1,ii*2-1});
289+
[~,tmp,tmp2] = fileparts(MRS_struct.metabfile{1,ii*2-1});
290290
else
291-
[~,tmp,filesExist] = fileparts(MRS_struct.metabfile{1,ii});
291+
[~,tmp,tmp2] = fileparts(MRS_struct.metabfile{1,ii});
292292
end
293-
fname = [tmp filesExist];
293+
fname = [tmp tmp2];
294294
if length(fname) > 30
295295
fname = [fname(1:12) '...' fname(end-11:end)];
296296
end

GannetVersion.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
str = char(str(:)');
1212
expression = '(?<field>MRS_struct.version.Gannet = )''(?<version>.*?)''';
1313
out = regexp(str, expression, 'names');
14-
fprintf('\n %s\n\n', out.version);
14+
fprintf('\nYour version of Gannet is %s\n\n', out.version);

0 commit comments

Comments
 (0)