Commit ff224692 authored by Mark van Turnhout's avatar Mark van Turnhout
Browse files

MRItoMat for mutiple basil-ids and update of help

parent 4522ea0f
function bas_MRItoMat(basil,overwrite)
% bas_MRItoMat(basil,bruker,overwrite)
% bas_MRItoMat(basil,overwrite)
%
% Reads raw MRI (meta) data from <MRIroot>/<MRIfolder> and copies it to the
% <basilhome>/<basil> work directory. The relation between <MRIfolder> and
% <basil> is hard-coded in bas_getMeta.
%
% Without arguments, all data defined in bas_getMeta is processed, and
% existing data will be overwritten in <basilhome>/<basil>. With a single
% argument, it is assumed that the function is called as
% bas_MRItoMat(overwrite). The argument overwrite is used to overwrite
% existing data in <basilhome>/<basil> (overwrite = 1, default), or to
% leave existing data in <basilhome>/<basil> intact (overwrite = 0).
%
% Output
% <basilhome>/<basil>/MRI_slices.mat, 3D matrix with MRI-slice voxel
% values
% <basilhome>/<basil>/IMDAT.mat, as MRI_slices.mat (for backward
% compatibility)
% <basilhome>/<basil>/MRI_subject.mat, 'subject' from MRI meta data
% <basilhome>/<basil>/MRI_acqp.mat, 'acqp' from MRI meta data
% <basilhome>/<basil>/MRI_method.mat, 'method' from MRI meta data
% <basilhome>/<basil>/MRI_imnd.mat, 'imnd' from MRI meta data
% <basilhome>/<basil>/MRI_reco.mat, 'reco' from MRI meta data
% <basilhome>/<basil>/MRI_d3proc.mat, 'd3proc' from MRI meta data
% <basilhome>/<basil>/MRI_visupars.mat, 'visupars' from MRI meta data
% <basilhome>/<basil>/MRI_voxel.txt, row with the voxel sizes in [x y z]
% in mm from MRI meta data
%
% See also, bas_getMRIroot, bas_getMeta, bas_getDataRoot, bas_readMRI,
% bas_readMRImeta, bas_prepFEM
if nargin < 2, overwrite = 1; end
if nargin < 1, basil = 0; end
bruker = bas_getMRIroot;
if nargin < 2, overwrite = 1; end
if nargin < 1, basil = bas_getMeta(0); basil = basil(:,1); end
[scans, paths] = bas_getMeta(basil);
bruker = bas_getMRIroot;
if ~exist(bruker,'dir'), bruker = uigetdir('~'); end
savenames = {''; '_preload'; '_loading'; '_postload'; '_flash'};
if ~exist(bruker,'dir'), bruker = uigetdir('~'); end
for b = 1:size(scans,1)
if ~exist(num2str(scans(b,1)),'dir'), mkdir(num2str(scans(b,1))); end
for s = 2:size(scans,2)
if (~exist( fullfile(pwd,num2str(scans(b,1)),savenames{s},'.mat'),'file') ...
|| overwrite == 1) && scans(b,s) > 0
% fullfile(bruker,paths(b),scans(b,s))
[data, subject, acqp, meth, imnd, reco, d3proc, visupars] = ...
bas_readMRI(fullfile(bruker,paths{b}),scans(b,s));
for d = 1:numel(basil)
[scans, paths] = bas_getMeta(basil(d));
for b = 1:size(scans,1)
if ~exist(num2str(scans(b,1)),'dir'), mkdir(num2str(scans(b,1))); end
for s = 2:size(scans,2)
Info.Parameters.Columns = meth.PVM_Matrix(1);
Info.Parameters.EchoNumber = acqp.NECHOES;
Info.Parameters.EchoTime = acqp.ACQ_echo_time;
% Info.Parameters.FlipAngle = meth.RfcFlipAngle;
Info.Parameters.ImageType = acqp.ACQ_method;
Info.Parameters.PatientID = visupars.VisuStudyId;
% Info.Parameters.PixelSpacing=[a b];
Info.Parameters.ProtocolName = acqp.ACQ_protocol_name;
Info.Parameters.RepititionTime = acqp.ACQ_repetition_time;
Info.Parameters.Rows = meth.PVM_Matrix(2);
Info.Parameters.SliceNumber = acqp.NECHOES;
Info.Parameters.SliceThickness = str2double(meth.PVM_SliceThick);% (in mm)
spatres = meth.PVM_SpatResol; %mm
if size(spatres,2)==3
Info.Parameters.VoxelSize=spatres;
else
Info.Parameters.VoxelSize=[spatres(1) spatres(2) ...
str2double(meth.PVM_SliceThick)];
if (~exist( fullfile(pwd,num2str(scans(b,1)),savenames{s},'.mat'),'file') ...
|| overwrite == 1) && scans(b,s) > 0
% fullfile(bruker,paths(b),scans(b,s))
[data, subject, acqp, meth, imnd, reco, d3proc, visupars] = ...
bas_readMRI(fullfile(bruker,paths{b}),scans(b,s));
Info.Parameters.Columns = meth.PVM_Matrix(1);
Info.Parameters.EchoNumber = acqp.NECHOES;
Info.Parameters.EchoTime = acqp.ACQ_echo_time;
% Info.Parameters.FlipAngle = meth.RfcFlipAngle;
Info.Parameters.ImageType = acqp.ACQ_method;
Info.Parameters.PatientID = visupars.VisuStudyId;
% Info.Parameters.PixelSpacing=[a b];
Info.Parameters.ProtocolName = acqp.ACQ_protocol_name;
Info.Parameters.RepititionTime = acqp.ACQ_repetition_time;
Info.Parameters.Rows = meth.PVM_Matrix(2);
Info.Parameters.SliceNumber = acqp.NECHOES;
Info.Parameters.SliceThickness = str2double(meth.PVM_SliceThick);% (in mm)
spatres = meth.PVM_SpatResol; %mm
if size(spatres,2)==3
Info.Parameters.VoxelSize=spatres;
else
Info.Parameters.VoxelSize=[spatres(1) spatres(2) ...
str2double(meth.PVM_SliceThick)];
end
voxel = Info.Parameters.VoxelSize; %#ok<NASGU>
Info.Parameters.ImagePositionPatient = visupars.VisuCorePosition;
Info.Parameters.ImageOrientationPatient = visupars.VisuCoreOrientation;
% check number of reconstruction
nrRecos = size(data{1, 1}.scan{1, 1}.Reconstruction,2);
for i = 1:nrRecos
Info.ImageReco{1,i} = data{1,1}.scan{1,1}.Reconstruction{1,i}.images(:,:,:);
end
slices = Info.ImageReco{1}; %#ok<NASGU>
save(fullfile(num2str(scans(b,1)),strcat('IMDAT',savenames{s},'.mat')),'Info'); % for backward compatibility
save(fullfile(num2str(scans(b,1)),strcat('MRI_slices',savenames{s},'.mat')),'slices');
if isstruct(subject)
save(fullfile(num2str(scans(b,1)),strcat('MRI_subject',savenames{s},'.mat')),'subject');
end
if isstruct(acqp)
save(fullfile(num2str(scans(b,1)),strcat('MRI_acqp',savenames{s},'.mat')),'acqp');
end
if isstruct(meth)
save(fullfile(num2str(scans(b,1)),strcat('MRI_method',savenames{s},'.mat')),'meth');
end
if isstruct(imnd)
save(fullfile(num2str(scans(b,1)),strcat('MRI_imnd',savenames{s},'.mat')),'imnd');
end
if isstruct(reco)
save(fullfile(num2str(scans(b,1)),strcat('MRI_reco',savenames{s},'.mat')),'reco');
end
if isstruct(d3proc)
save(fullfile(num2str(scans(b,1)),strcat('MRI_d3proc',savenames{s},'.mat')),'d3proc');
end
if isstruct(visupars)
save(fullfile(num2str(scans(b,1)),strcat('MRI_visupars',savenames{s},'.mat')),'visupars');
end
save(fullfile(num2str(scans(b,1)),strcat('MRI_voxel',savenames{s},'.txt')),'voxel', '-ascii');
end
voxel = Info.Parameters.VoxelSize; %#ok<NASGU>
Info.Parameters.ImagePositionPatient = visupars.VisuCorePosition;
Info.Parameters.ImageOrientationPatient = visupars.VisuCoreOrientation;
% check number of reconstruction
nrRecos = size(data{1, 1}.scan{1, 1}.Reconstruction,2);
for i = 1:nrRecos
Info.ImageReco{1,i} = data{1,1}.scan{1,1}.Reconstruction{1,i}.images(:,:,:);
end
slices = Info.ImageReco{1}; %#ok<NASGU>
save(fullfile(num2str(scans(b,1)),strcat('IMDAT',savenames{s},'.mat')),'Info'); % for backward compatibility
save(fullfile(num2str(scans(b,1)),strcat('MRI_slices',savenames{s},'.mat')),'slices');
if isstruct(subject)
save(fullfile(num2str(scans(b,1)),strcat('MRI_subject',savenames{s},'.mat')),'subject');
end
if isstruct(acqp)
save(fullfile(num2str(scans(b,1)),strcat('MRI_acqp',savenames{s},'.mat')),'acqp');
end
if isstruct(meth)
save(fullfile(num2str(scans(b,1)),strcat('MRI_method',savenames{s},'.mat')),'meth');
end
if isstruct(imnd)
save(fullfile(num2str(scans(b,1)),strcat('MRI_imnd',savenames{s},'.mat')),'imnd');
end
if isstruct(reco)
save(fullfile(num2str(scans(b,1)),strcat('MRI_reco',savenames{s},'.mat')),'reco');
end
if isstruct(d3proc)
save(fullfile(num2str(scans(b,1)),strcat('MRI_d3proc',savenames{s},'.mat')),'d3proc');
end
if isstruct(visupars)
save(fullfile(num2str(scans(b,1)),strcat('MRI_visupars',savenames{s},'.mat')),'visupars');
end
save(fullfile(num2str(scans(b,1)),strcat('MRI_voxel',savenames{s},'.txt')),'voxel', '-ascii');
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment