Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] - Defacing of structural images - OspreyCoreg/Seg -… #552

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions coreg/OspreyCoreg.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@
end
end

if MRSCont.opts.img.deface
[anaon_vol_image] = spm_deface({vol_image.fname});
saveDestinationAnon = fullfile(MRSCont.outputFolder, 'DefacedNII'); %CWDJ - Address in future update
if ~exist(saveDestinationAnon,'dir')
mkdir(saveDestinationAnon);
end
[~,AnonName,AnonExt] = fileparts(anaon_vol_image{1});
[~] = movefile(anaon_vol_image{1}, fullfile(saveDestinationAnon,[AnonName AnonExt]));
vol_image = spm_vol(fullfile(saveDestinationAnon,[AnonName AnonExt]));
end

% Save back the image and voxel mask volumes to MRSCont
MRSCont.coreg.vol_image{kk} = vol_image;
MRSCont.coreg.vol_mask{kk} = vol_mask;
Expand Down
4 changes: 4 additions & 0 deletions exampledata/ima/jobIMA.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@
% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
6 changes: 5 additions & 1 deletion exampledata/nifti-mrs/jobNIfTIMRS.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@

% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
6 changes: 5 additions & 1 deletion exampledata/p/jobP.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@

% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
4 changes: 4 additions & 0 deletions exampledata/rda/jobRDA.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@
% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
4 changes: 4 additions & 0 deletions exampledata/sdat/MEGA/jobSDAT_MEGA.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@
% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
4 changes: 4 additions & 0 deletions exampledata/sdat/MEGA/jobSDAT_MEGA_Multidataset.m
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@
% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
4 changes: 4 additions & 0 deletions exampledata/sdat/UnEdited/jobSDAT.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
4 changes: 4 additions & 0 deletions exampledata/sdat/UnEdited_with_MM_data/jobSDAT_MM.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
4 changes: 4 additions & 0 deletions exampledata/twix/jobTwix.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
% Optional: In case the automatic basisset picker is not working you can manually
% select the path to the basis set in the osprey/fit/basis, i.e.:
% opts.fit.basisSetFile = 'osprey/fit/basis/3T/philips/mega/press/gaba68/basis_philips_megapress_gaba68.mat';

% Optional: Deface the strucutral images in the Coreg/Seg figures for HIPAA
% compliance
opts.img.deface = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Expand Down
Binary file added graphics/osprey.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 20 additions & 2 deletions job/OspreyJob.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@
fprintf('Adding macromolecule and lipid basis functions to the fit (default). Please indicate otherwise in the csv-file or the GUI \n');
MRSCont.opts.fit.fitMM = 1;
end

if isfield(jobStruct,'deface')
MRSCont.opts.img.deface = jobStruct.deface;
else
fprintf('Structrual images are not defaced (default). Please indicate otherwise in the csv-file or the GUI \n');
MRSCont.opts.img.deface = 0;
end
end

%%% 3b. LOAD JSON FILE %%%
Expand Down Expand Up @@ -388,6 +393,11 @@
opts.fit.basisSetFile = jobStruct.basisSet;
end
end
if isfield(jobStruct,'deface')
opts.img.deface = jobStruct.deface;
else
opts.img.deface = 0;
end
debug = '11';
end

Expand Down Expand Up @@ -538,7 +548,9 @@
end
if isfield(opts.fit, 'coMM3')
MRSCont.opts.fit.coMM3 = opts.fit.coMM3;
MRSCont.opts.fit.FWHMcoMM3 = opts.fit.FWHMcoMM3;
if isfield(opts.fit, 'FWHMcoMM3')
MRSCont.opts.fit.FWHMcoMM3 = opts.fit.FWHMcoMM3;
end
else
MRSCont.opts.fit.coMM3 = 'freeGauss';
MRSCont.opts.fit.FWHMcoMM3 = 14;
Expand Down Expand Up @@ -640,6 +652,12 @@
MRSCont.flags.hasStatfile = 0;
end

%Change deface option for images
if isfield(opts, 'img')
if isfield(opts.img, 'deface')
MRSCont.opts.img.deface = opts.img.deface;
end
end

%%% 5. SAVE FILE/FOLDER NAMES INTO MRSCONT %%%
% Make sure that the mandatory fields (metabolite data; output folder) are
Expand Down
101 changes: 97 additions & 4 deletions load/osp_LoadNII.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,73 @@
% Read in the raw metabolite data.
metab_ll = MRSCont.opts.MultipleSpectra.metab(ll);
raw = io_loadspec_niimrs(MRSCont.files{metab_ll,kk});
raw.flags.isUnEdited = MRSCont.flags.isUnEdited;

% If the sequence flags are not parsed form the nii header
if sum([raw.flags.isUnEdited raw.flags.isMEGA raw.flags.isHERMES raw.flags.isHERCULES]) == 0
if MRSCont.flags.isUnEdited
raw.flags.isUnEdited = 1;
end
if MRSCont.flags.isMEGA
raw.flags.isMEGA = 1;
end
if MRSCont.flags.isHERMES
raw.flags.isHERMES = 1;
end
if MRSCont.flags.isHERCULES
raw.flags.isHERCULES = 1;
end
end

% Read in the MM data.
% Leave until we have example data.

% Read in the raw water reference data.
if MRSCont.flags.hasRef
ref_ll = MRSCont.opts.MultipleSpectra.ref(ll);
raw_ref = io_loadspec_niimrs(MRSCont.files_ref{ref_ll,kk});
raw_ref.flags.isUnEdited = MRSCont.flags.isUnEdited;
% If the sequence flags are not parsed form the nii header
if sum([raw_ref.flags.isUnEdited raw_ref.flags.isMEGA raw_ref.flags.isHERMES raw_ref.flags.isHERCULES]) == 0
if MRSCont.flags.isUnEdited
raw_ref.flags.isUnEdited = 1;
end
if MRSCont.flags.isMEGA
raw_ref.flags.isMEGA = 1;
end
if MRSCont.flags.isHERMES
raw_ref.flags.isHERMES = 1;
end
if MRSCont.flags.isHERCULES
raw_ref.flags.isHERCULES = 1;
end
end

end

% Read in the short-TE water data.
if MRSCont.flags.hasWater
w_ll = MRSCont.opts.MultipleSpectra.w(ll);
raw_w = io_loadspec_niimrs(MRSCont.files_w{w_ll,kk});
raw_w.flags.isUnEdited = MRSCont.flags.isUnEdited;
% If the sequence flags are not parsed form the nii header
if sum([raw_w.flags.isUnEdited raw_w.flags.isMEGA raw_w.flags.isHERMES raw_w.flags.isHERCULES]) == 0
if MRSCont.flags.isUnEdited
raw_w.flags.isUnEdited = 1;
end
if MRSCont.flags.isMEGA
raw_w.flags.isMEGA = 1;
end
if MRSCont.flags.isHERMES
raw_w.flags.isHERMES = 1;
end
if MRSCont.flags.isHERCULES
raw_w.flags.isHERCULES = 1;
end
end

end





% Set flag and save data under appropriate name
if raw.dims.coils == 0
Expand Down Expand Up @@ -127,6 +176,28 @@
% Set flag and save data under appropriate name
if raw.dims.coils == 0
MRSCont.flags.coilsCombined = 1;
% Do some houskeeping on the metabolite data if the nii-mrs conversion
% did not work correctly
if (raw.flags.isMEGA || raw.flags.isHERMES || raw.flags.isHERCULES) && (raw.dims.subSpecs == 0)
if raw.flags.isMEGA
raw.fids = reshape(raw.fids,[raw.sz(raw.dims.t) raw.sz(raw.dims.averages)/2 2]);
raw.specs = reshape(raw.specs,[raw.sz(raw.dims.t) raw.sz(raw.dims.averages)/2 2]);
raw.averages = raw.sz(raw.dims.averages)/2;
raw.sz = size(raw.fids);
raw.subspecs = 2;
raw.rawSubspecs = 2;
raw.dims.subSpecs = 3;
end
if raw.flags.isHERMES || raw.flags.isHERCULES
raw.fids = reshape(raw.fids,[raw.sz(raw.dims.t) raw.sz(raw.dims.averages)/4 4]);
raw.specs = reshape(raw.specs,[raw.sz(raw.dims.t) raw.sz(raw.dims.averages)/4 4]);
raw.averages = raw.sz(raw.dims.averages)/4;
raw.sz = size(raw.fids);
raw.subspecs = 4;
raw.rawSubspecs = 4;
raw.dims.subSpecs = 3;
end
end
MRSCont.raw{kk} = raw;
if MRSCont.flags.hasRef
MRSCont.raw_ref{kk} = raw_ref;
Expand All @@ -135,9 +206,30 @@
if MRSCont.flags.hasWater
MRSCont.raw_w{kk} = raw_w;
end

else
MRSCont.flags.coilsCombined = 0;
% Do some houskeeping on the metabolite data if the nii-mrs conversion
% did not work correctly
if (raw.flags.isMEGA || raw.flags.isHERMES || raw.flags.isHERCULES) && (raw.dims.subSpecs == 0)
if raw.flags.isMEGA
raw.fids = reshape(raw.fids,[raw.sz(raw.dims.t) raw.sz(raw.dims.coils) raw.sz(raw.dims.averages)/2 2]);
raw.specs = reshape(raw.specs,[raw.sz(raw.dims.t) raw.sz(raw.dims.coils) raw.sz(raw.dims.averages)/2 2]);
raw.averages = raw.sz(raw.dims.averages)/2;
raw.sz = size(raw.fids);
raw.subspecs = 2;
raw.rawSubspecs = 2;
raw.dims.subSpecs = 4;
end
if raw.flags.isHERMES || raw.flags.isHERCULES
raw.fids = reshape(raw.fids,[raw.sz(raw.dims.t) raw.sz(raw.dims.coils) raw.sz(raw.dims.averages)/4 4]);
raw.specs = reshape(raw.specs,[raw.sz(raw.dims.t) raw.sz(raw.dims.coils) raw.sz(raw.dims.averages)/4 4]);
raw.averages = raw.sz(raw.dims.averages)/4;
raw.sz = size(raw.fids);
raw.subspecs = 4;
raw.rawSubspecs = 4;
raw.dims.subSpecs = 4;
end
end
MRSCont.raw_uncomb{kk} = raw;
if MRSCont.flags.hasRef
MRSCont.raw_ref_uncomb{kk} = raw_ref;
Expand All @@ -147,6 +239,7 @@
MRSCont.raw_w_uncomb{kk} = raw_w;
end
end

end
% Try to get some params from NIFTI
if isfield(raw.nii_mrs.hdr_ext,'Manufacturer')
Expand Down
1 change: 1 addition & 0 deletions settings/OspreySettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
MRSCont.opts.ECC.mm = 1; % Do ECC for all metabolite-nulled spectra.
MRSCont.opts.cosmetics.LB = 0; % Do cosmetic LB
MRSCont.opts.cosmetics.Zoom = 2.75; % Do cosmetic Zoom
MRSCont.opts.img.deface = 0; % Deface data
%%% 2. FIND AND SET PATHS %%%
% Osprey
[settingsFolder,~,~] = fileparts(which('OspreySettings.m'));
Expand Down
2 changes: 1 addition & 1 deletion utilities/RunOspreyJob.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
% MRSCont = RunOspreyJob(jobFilePath)
%
% INPUTS:
% jobFilePath = path to the Osprey jobfile (.m, .csv or .jason).
% jobFilePath = path to the Osprey jobfile (.m, .csv or .json).
%
% OUTPUTS:
% MRSCont = Osprey MRS data container.
Expand Down