Skip to content

Commit

Permalink
Merge pull request #10 from markmikkelsen/dev
Browse files Browse the repository at this point in the history
Merge with dev; release of v3.3.0
  • Loading branch information
markmikkelsen authored Oct 22, 2022
2 parents 287076a + b2a13e4 commit 8aad18d
Show file tree
Hide file tree
Showing 64 changed files with 16,556 additions and 1,801 deletions.
4 changes: 3 additions & 1 deletion AlignSubSpectra.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
else
subSpecInd = [3 2 1 4];
end
case 'NIfTI'
subSpecInd = [3 2 1 4];
case {'Philips','Philips_data','Philips_raw'}
subSpecInd = [1 2 3 4];
case {'Siemens_twix','Siemens_rda','Siemens_dicom'}
Expand All @@ -87,7 +89,7 @@
end
else
switch MRS_struct.p.vendor
case 'GE'
case {'GE','NIfTI'}
subSpecInd = [3 2 1 4];
case {'Philips','Philips_data','Philips_raw'}
subSpecInd = [1 4 3 2];
Expand Down
2 changes: 2 additions & 0 deletions AlignSubSpectra_PreAlignRef.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
end
else
switch MRS_struct.p.vendor
case 'GE'
subSpecInd = [3 2 1 4];
case {'Philips','Philips_data','Philips_raw'}
subSpecInd = [1 4 3 2];
case {'Siemens_twix','Siemens_rda','Siemens_dicom'}
Expand Down
47 changes: 33 additions & 14 deletions CoRegStandAlone/CoReg.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

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

MRS_struct.version.coreg = '210701';
loadFile = which('GannetCoRegister');
fileID = fopen(loadFile, 'rt');
str = fread(fileID, Inf, '*uchar');
fclose(fileID);
str = char(str(:)');
expression = '(?<field>MRS_struct.version.coreg = )''(?<version>.*?)''';
out = regexp(str, expression, 'names');
MRS_struct.version.coreg = out.version;

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

Expand Down Expand Up @@ -33,6 +40,17 @@

%Ultimately this switch will not be necessary...
switch MRS_struct.p.vendor

case 'GE'
[~,~,ext] = fileparts(struc{ii});
if strcmp(ext,'.nii')
MRS_struct = GannetMask_GE_nii(MRS_struct.metabfile{ii}, struc{ii}, MRS_struct, ii, vox, kk);
else
MRS_struct = GannetMask_GE(MRS_struct.metabfile{ii}, struc{ii}, MRS_struct, ii, vox, kk);
end

case 'NIfTI'
MRS_struct = GannetMask_NIfTI(MRS_struct.metabfile{ii}, struc{ii}, MRS_struct, ii, vox, kk);

case 'Philips'
sparname = [MRS_struct.metabfile{ii}(1:(end-4)) MRS_struct.p.spar_string];
Expand Down Expand Up @@ -66,24 +84,20 @@
case 'Siemens_rda'
MRS_struct = GannetMask_SiemensRDA(MRS_struct.metabfile{ii}, struc{ii}, MRS_struct, ii, vox, kk);

case {'Siemens_twix', 'Siemens_dicom', 'dicom'}
case {'Siemens_twix', 'Siemens_dicom', 'DICOM'}
MRS_struct = GannetMask_SiemensTWIX(MRS_struct.metabfile{ii}, struc{ii}, MRS_struct, ii, vox, kk);

case 'GE'
[~,~,ext] = fileparts(struc{ii});
if strcmp(ext,'.nii')
MRS_struct = GannetMask_GE_nii(MRS_struct.metabfile{ii}, struc{ii}, MRS_struct, ii, vox, kk);
else
MRS_struct = GannetMask_GE(MRS_struct.metabfile{ii}, struc{ii}, MRS_struct, ii, vox, kk);
end

end

% Build output figure
if ishandle(103)
clf(103);
end
h = figure(103);
if MRS_struct.p.hide
h = figure('Visible', 'off');
else
h = figure(103);
end
scr_sz = get(0,'ScreenSize');
fig_w = 1000;
fig_h = 707;
Expand Down Expand Up @@ -150,16 +164,16 @@
imagesc(squeeze(MRS_struct.mask.(vox{kk}).img{ii}));
colormap('gray');
img = MRS_struct.mask.(vox{kk}).img{ii}(:);
caxis([0 mean(img(img > 0.01)) + 3*std(img(img > 0.01))]);
caxis([0 mean(img(img > 0.01)) + 3*std(img(img > 0.01))]); %#ok<*CAXIS>
axis equal tight off;
text(10, size(MRS_struct.mask.(vox{kk}).img{ii},1)/2, 'L', 'Color', [1 1 1], 'FontSize', 20);
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);
set(ha,'pos',[0 0.15 1 1]);
title(t, 'FontName', 'Arial', 'FontSize', 15, 'Interpreter', 'none');

% Gannet logo
Gannet_logo = fullfile(fileparts(which('GannetLoad')), 'Gannet3_logo.png');
I = imread(Gannet_logo,'png','BackgroundColor',[1 1 1]);
Gannet_logo = fullfile(fileparts(which('GannetLoad')), 'Gannet3_logo.jpg');
I = imread(Gannet_logo);
axes('Position', [0.825, 0.05, 0.125, 0.125]);
imshow(I);
text(0.9, 0, MRS_struct.version.Gannet, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 14, 'FontWeight', 'bold', 'HorizontalAlignment', 'left');
Expand Down Expand Up @@ -209,5 +223,10 @@

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

% Need to close hidden figures to show figures after Gannet is done running
if MRS_struct.p.hide
close(figTitle);
end



49 changes: 34 additions & 15 deletions CoRegStandAlone/CoRegStandAlone.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,40 @@
% 2020-07-29: Some minor cosmetic changes.
% 2022-06-03: Fixed bug related to target metabolite

if nargin == 0
error('MATLAB:minrhs','Not enough input arguments.');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1. Pre-initialise
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

MRS_struct.version.Gannet = '3.2.1';
MRS_struct.version.load = '220607';
loadFile = which('GannetLoad');
fileID = fopen(loadFile, 'rt');
str = fread(fileID, Inf, '*uchar');
fclose(fileID);
str = char(str(:)');
expression = '(?<field>MRS_struct.version.Gannet = )''(?<version>.*?)''';
out = regexp(str, expression, 'names');
MRS_struct.version.Gannet = out.version;

expression = '(?<field>MRS_struct.version.load = )''(?<version>.*?)''';
out = regexp(str, expression, 'names');
MRS_struct.version.load = out.version;

MRS_struct.ii = 0;
if size(metabfile,2) == 1
metabfile = metabfile';
end
MRS_struct.metabfile = metabfile;
MRS_struct.p.HERMES = 0;
MRS_struct.p.HERMES = 0;

% Flags
MRS_struct.p.mat = 1; % Save results in *.mat file? (0 = NO, 1 = YES (default)).
MRS_struct.p.mat = 0; % Save results in *.mat file? (0 = NO, 1 = YES (default)).
MRS_struct.p.csv = 1; % Save results in *.csv file? (0 = NO, 1 = YES (default)).
MRS_struct.p.vox = {'vox1'}; % Name of the voxel
MRS_struct.p.target = {'GABAGlx'}; % Name of the target metabolite
MRS_struct.p.hide = 0; % Do not display output figures

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2. Determine data parameters from header
Expand All @@ -75,20 +91,14 @@

switch MRS_struct.p.vendor

case 'DICOM'
MRS_struct = DICOMRead(MRS_struct, metabfile{ii});

case 'GE'
MRS_struct = GERead(MRS_struct, metabfile{ii});

case 'Siemens_twix'
MRS_struct = SiemensTwixRead(MRS_struct, metabfile{ii});

case 'Siemens_dicom'
MRS_struct = SiemensDICOMRead(MRS_struct, metabfile{ii});

case 'dicom'
MRS_struct = DICOMRead(MRS_struct, metabfile{ii});

case 'Siemens_rda'
MRS_struct = SiemensRead(MRS_struct, metabfile{ii}, metabfile{ii});
case 'NIfTI'
MRS_struct = NIfTIMRSRead(MRS_struct, metabfile{ii});

case 'Philips'
MRS_struct = PhilipsRead(MRS_struct, metabfile{ii});
Expand All @@ -99,6 +109,15 @@
case 'Philips_raw'
MRS_struct = PhilipsRawLoad(MRS_struct, metabfile{ii}, 3, 0);

case 'Siemens_dicom'
MRS_struct = SiemensDICOMRead(MRS_struct, metabfile{ii});

case 'Siemens_rda'
MRS_struct = SiemensRead(MRS_struct, metabfile{ii}, metabfile{ii});

case 'Siemens_twix'
MRS_struct = SiemensTwixRead(MRS_struct, metabfile{ii});

end

end
Expand Down
26 changes: 21 additions & 5 deletions CoRegStandAlone/Seg.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
% This is useful if only the tissue segmentation information is supposed to
% be obtained.

MRS_struct.version.segment = '220607';
vox = MRS_struct.p.vox(1);
loadFile = which('GannetSegment');
fileID = fopen(loadFile, 'rt');
str = fread(fileID, Inf, '*uchar');
fclose(fileID);
str = char(str(:)');
expression = '(?<field>MRS_struct.version.segment = )''(?<version>.*?)''';
out = regexp(str, expression, 'names');
MRS_struct.version.segment = out.version;

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

Expand All @@ -29,6 +35,7 @@
error(msg);
end

vox = MRS_struct.p.vox(1);
kk = 1;
setup_spm = 1;

Expand Down Expand Up @@ -159,7 +166,11 @@
if ishandle(104)
clf(104);
end
h = figure(104);
if MRS_struct.p.hide
h = figure('Visible', 'off');
else
h = figure(104);
end
% Open figure in center of screen
scr_sz = get(0,'ScreenSize');
fig_w = 1000;
Expand Down Expand Up @@ -237,8 +248,8 @@
title(t, 'FontName', 'Arial', 'FontSize', 15, 'Interpreter', 'none');

% Gannet logo
Gannet_logo = fullfile(fileparts(which('GannetLoad')), 'Gannet3_logo.png');
I = imread(Gannet_logo,'png','BackgroundColor',[1 1 1]);
Gannet_logo = fullfile(fileparts(which('GannetLoad')), 'Gannet3_logo.jpg');
I = imread(Gannet_logo);
axes('Position', [0.825, 0.05, 0.125, 0.125]);
imshow(I);
text(0.9, 0, MRS_struct.version.Gannet, 'Units', 'normalized', 'FontName', 'Arial', 'FontSize', 14, 'FontWeight', 'bold', 'HorizontalAlignment', 'left');
Expand Down Expand Up @@ -296,6 +307,11 @@

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

% Need to close hidden figures to show figures after Gannet is done running
if MRS_struct.p.hide
close(figTitle);
end


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

Expand Down
64 changes: 34 additions & 30 deletions DICOMRead.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
folder = '.';
end
dcm_file_list = dir(fullfile(folder, '*.dcm')); % GO 11/16/2016
fprintf('\n%d water-suppressed DCM files detected in %s', length(dcm_file_list), folder);
fprintf('\n%d water-suppressed DICOM files found in %s', length(dcm_file_list), folder);

% Ordering of these files is not correct (i.e. 1,10,100,101...). Sort
% naturally.
Expand All @@ -60,40 +60,39 @@
%%% /PREPARATION %%%

%%% HEADER INFO PARSING %%%
DicomHeader = read_dcm_header(metabfile);
MRS_struct.p.seq = DicomHeader.sequenceFileName;
MRS_struct.p.TR(ii) = DicomHeader.TR;
MRS_struct.p.TE(ii) = DicomHeader.TE;
MRS_struct.p.npoints(ii) = DicomHeader.vectorSize;
MRS_struct.p.Navg(ii) = 2*DicomHeader.nAverages;
MRS_struct.p.nrows(ii) = 2*DicomHeader.nAverages;
MRS_struct.p.sw(ii) = 1/DicomHeader.dwellTime * 1E9 * 0.5; % check with oversampling? hence factor 0.5, need to figure out why <=> probably dataset with 512 points, oversampled is 1024
MRS_struct.p.LarmorFreq(ii) = DicomHeader.tx_freq * 1E-6;
MRS_struct.p.voxdim(ii,1) = DicomHeader.VoI_PeFOV;
MRS_struct.p.voxdim(ii,2) = DicomHeader.VoI_RoFOV;
MRS_struct.p.voxdim(ii,3) = DicomHeader.VoIThickness;
DicomHeader = read_dcm_header(metabfile);
MRS_struct.p.seq = DicomHeader.sequenceFileName;
MRS_struct.p.TR(ii) = DicomHeader.TR;
MRS_struct.p.TE(ii) = DicomHeader.TE;
MRS_struct.p.npoints(ii) = DicomHeader.vectorSize;
MRS_struct.p.Navg(ii) = 2*DicomHeader.nAverages;
MRS_struct.p.nrows(ii) = 2*DicomHeader.nAverages;
MRS_struct.p.sw(ii) = 1/DicomHeader.dwellTime * 1E9 * 0.5; % check with oversampling? hence factor 0.5, need to figure out why <=> probably dataset with 512 points, oversampled is 1024
MRS_struct.p.LarmorFreq(ii) = DicomHeader.tx_freq * 1E-6;
MRS_struct.p.voxdim(ii,1) = DicomHeader.VoI_PeFOV;
MRS_struct.p.voxdim(ii,2) = DicomHeader.VoI_RoFOV;
MRS_struct.p.voxdim(ii,3) = DicomHeader.VoIThickness;
MRS_struct.p.VoI_InPlaneRot(ii) = DicomHeader.VoI_InPlaneRot;
MRS_struct.p.voxoff(ii,1) = DicomHeader.PosSag;
MRS_struct.p.voxoff(ii,2) = DicomHeader.PosCor;
MRS_struct.p.voxoff(ii,3) = DicomHeader.PosTra;
MRS_struct.p.NormCor(ii) = DicomHeader.NormCor;
MRS_struct.p.NormSag(ii) = DicomHeader.NormSag;
MRS_struct.p.NormTra(ii) = DicomHeader.NormTra;
MRS_struct.p.voxoff(ii,1) = DicomHeader.PosSag;
MRS_struct.p.voxoff(ii,2) = DicomHeader.PosCor;
MRS_struct.p.voxoff(ii,3) = DicomHeader.PosTra;
MRS_struct.p.NormCor(ii) = DicomHeader.NormCor;
MRS_struct.p.NormSag(ii) = DicomHeader.NormSag;
MRS_struct.p.NormTra(ii) = DicomHeader.NormTra;
%%% /HEADER INFO PARSING %%%

%%% DATA LOADING %%%
% Preallocate array in which the FIDs are to be extracted.
MRS_struct.fids.data = zeros(MRS_struct.p.npoints(ii),length(dcm_file_names));
MRS_struct.fids.data = zeros(MRS_struct.p.npoints(ii), length(dcm_file_names));

% Collect all FIDs and sort them into MRS_struct
for kk = 1:length(dcm_file_names)

% Open IMA
fd = dicom_open(dcm_file_names{kk});

% read the signal in as a complex FID
MRS_struct.fids.data(:,kk) = dicom_get_spectrum_siemens(fd);

fclose(fd);
end

Expand All @@ -116,30 +115,35 @@

% Set up the file name array.
if nargin == 3

%%% WATER HEADER INFO PARSING %%%
DicomHeaderWater = read_dcm_header(waterfile);
MRS_struct.p.TR_water(ii) = DicomHeaderWater.TR;
MRS_struct.p.TE_water(ii) = DicomHeaderWater.TE;
%%% /WATER HEADER INFO PARSING %%%

waterfolder = fileparts(waterfile);
if isempty(waterfile)
waterfolder = '.';
end
water_file_list = dir(fullfile(waterfolder, '*.dcm'));
fprintf('\n%d water-unsuppressed DCM files detected in %s', length(water_file_list), waterfolder);
fprintf('\n%d water-unsuppressed DICOM files found in %s', length(water_file_list), waterfolder);
water_file_names = sort_nat({water_file_list.name});
water_file_names = strcat(waterfolder, filesep, water_file_names);

% Load the actual water-unsuppressed data.
MRS_struct.fids.waterdata = zeros(MRS_struct.p.npoints(ii), length(water_file_names));

% Collect all FIDs and sort them into MRS_struct
for kk = 1:length(water_file_names)
for kk = 1:length(water_file_names)
% Open IMA
fd = dicom_open(water_file_names{kk});
fd = dicom_open(water_file_names{kk});
% read the signal in as a complex FID
MRS_struct.fids.data_water(:,kk) = dicom_get_spectrum_siemens(fd);
MRS_struct.fids.data_water(:,kk) = dicom_get_spectrum_siemens(fd);
fclose(fd);
end
MRS_struct.fids.data_water = mean(MRS_struct.fids.data_water,2);

end
%%% /WATER DATA LOADING %%%

Expand Down
Loading

0 comments on commit 8aad18d

Please sign in to comment.