diff --git a/.gitignore b/.gitignore index 0a2025f..9dbbd44 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ !.gitignore .DS_Store +Elastix +MRIToolkitDefineLocalVars.m \ No newline at end of file diff --git a/CommandLine/mrtd_deconv_fod.m b/CommandLine/mrtd_deconv_fod.m index 4293d28..d89288f 100644 --- a/CommandLine/mrtd_deconv_fod.m +++ b/CommandLine/mrtd_deconv_fod.m @@ -77,7 +77,7 @@ function mrtd_deconv_fod(varargin) elseif(strcmp(value,'-iso_rf')) iso_rf(end+1) = {coptions{input_id+1}}; elseif(strcmp(value,'-mat')) - mat_file = {coptions{input_id+1}}; + mat_file = coptions{input_id+1}; end end diff --git a/CommandLine/mrtd_preproc.m b/CommandLine/mrtd_preproc.m index b44d498..f8ef9d2 100644 --- a/CommandLine/mrtd_preproc.m +++ b/CommandLine/mrtd_preproc.m @@ -247,12 +247,20 @@ function mrtd_preproc(varargin) V(~isfinite(V)) = 0; V2(~isfinite(V2)) = 0; subplot(1,2,1) - imagesc(V,[0 prctile(V(:),95)]); + max_value = prctile(V(:),95); + if(max_value == 0) + max_value = eps; + end + imagesc(V,[0 max_value]); axis image; % this ensures that getframe() returns a consistent size axis off; drawnow subplot(1,2,2) - imagesc(V2,[0 prctile(V2(:),95)]); + max_value = prctile(V2(:),95); + if(max_value == 0) + max_value = eps; + end + imagesc(V2,[0 max_value]); axis image; % this ensures that getframe() returns a consistent size axis off; drawnow diff --git a/ExploreDTIInterface/EDTI_Library.m b/ExploreDTIInterface/EDTI_Library.m index 3b0883c..1a4d3fc 100644 --- a/ExploreDTIInterface/EDTI_Library.m +++ b/ExploreDTIInterface/EDTI_Library.m @@ -345,13 +345,15 @@ function E_DTI_SMECEPI_Single(f_in,par) for i=1:Le - A = textread(trafo_names{i},'%s'); + % A = textread(trafo_names{i},'%s'); - DM_info{i}{1} = ... - [str2num(A{7})*(180/pi) str2num(A{6})*(180/pi) str2num(A{8})*(180/pi); - str2num(A{16}) str2num(A{15}) str2num(A{17}(1:end-1)); - str2num(A{13}) str2num(A{12}) str2num(A{14}); - str2num(A{10}) str2num(A{9}) str2num(A{11})]; + % DM_info{i}{1} = ... + % [str2num(A{7})*(180/pi) str2num(A{6})*(180/pi) str2num(A{8})*(180/pi); + % str2num(A{16}) str2num(A{15}) str2num(A{17}(1:end-1)); + % str2num(A{13}) str2num(A{12}) str2num(A{14}); + % str2num(A{10}) str2num(A{9}) str2num(A{11})]; + + DM_info{i}{1} = ImageRegistrations.ElastixRotationMatrix(trafo_names{i}); DM_info{i}{2} = EDTI_Library.E_DTI_Tra_Par_2_Tra_Mat(DM_info{i}{1}); diff --git a/ImageRegistrations/DW_Elastix_Register.m b/ImageRegistrations/DW_Elastix_Register.m index e3ddb44..3958118 100644 --- a/ImageRegistrations/DW_Elastix_Register.m +++ b/ImageRegistrations/DW_Elastix_Register.m @@ -2,8 +2,6 @@ %%% Alberto De Luca - alberto@isi.uu.nl $%%% %%% Distributed under the terms of LGPLv3 %%% - - function DW_Elastix_Register(moving,fixed,regparlist,output_dir,mMask,fMask,outfilename) global MRIToolkit; if(isfield(MRIToolkit,'Elastix')) diff --git a/ImageRegistrations/DW_Elastix_Transform.m b/ImageRegistrations/DW_Elastix_Transform.m index 909cd3a..f0ac46d 100644 --- a/ImageRegistrations/DW_Elastix_Transform.m +++ b/ImageRegistrations/DW_Elastix_Transform.m @@ -2,8 +2,6 @@ %%% Alberto De Luca - alberto@isi.uu.nl $%%% %%% Distributed under the terms of LGPLv3 %%% - - function DW_Elastix_Transform(filein,fileout,transform_parameters) global MRIToolkit; if(isfield(MRIToolkit,'Elastix')) diff --git a/ImageRegistrations/ImageRegistrations.m b/ImageRegistrations/ImageRegistrations.m new file mode 100644 index 0000000..3755e3c --- /dev/null +++ b/ImageRegistrations/ImageRegistrations.m @@ -0,0 +1,101 @@ +%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%% +%%% Alberto De Luca - alberto@isi.uu.nl $%%% +%%% Distributed under the terms of LGPLv3 %%% + +classdef ImageRegistrations < handle + methods(Static) + function elastix_cmd = BasicElastixCall() + global MRIToolkit; + if(isfield(MRIToolkit,'Elastix')) + elastix_path = MRIToolkit.Elastix.Location; + elastix_cmd = MRIToolkit.Elastix.ElastixCMD; + if(~ispc) + if(~ismac) + elastix_cmd = ['LD_LIBRARY_PATH=' elastix_path ' ' elastix_cmd]; + else + elastix_cmd = ['DYLD_LIBRARY_PATH=' elastix_path ' ' elastix_path 'elastix_Mac_64']; + end + end + end + end + + function transformix_cmd = BasicTransformixCall() + global MRIToolkit; + if(isfield(MRIToolkit,'Elastix')) + elastix_path = MRIToolkit.Elastix.Location; + transformix_cmd = MRIToolkit.Elastix.TransformixCMD; + if(~ispc) + if(~ismac) + transformix_cmd = ['LD_LIBRARY_PATH=' elastix_path ' ' transformix_cmd]; + else + transformix_cmd = ['DYLD_LIBRARY_PATH=' elastix_path ' ' transformix_cmd]; + end + end + end + end + + function TransfPar = ElastixRotationMatrix(elastix_transform_file) + TransfPar = []; + + if(exist(elastix_transform_file,"file") < 1) + disp('Cannot find the specified file') + return + end + + f = fopen(elastix_transform_file,'rt'); + + parameters = {}; + while(feof(f) == false) + l = fgetl(f); + if(contains(l,'(TransformParameters')) + l = strrep(l,'(',''); + l = strrep(l,')',''); + parameters = strsplit(l); + parameters = parameters(2:end); + break + end + end + + fclose(f); + + TransfPar = [ + str2double(parameters{2})*(180/pi) str2double(parameters{1})*(180/pi) str2double(parameters{3})*(180/pi); + str2double(parameters{11}) str2double(parameters{10}) str2double(parameters{12}); + str2double(parameters{8}) str2double(parameters{7}) str2double(parameters{9}); + str2double(parameters{5}) str2double(parameters{4}) str2double(parameters{6}) + ]; + TransfPar(isnan(TransfPar)) = 0; + end + + function DownloadElastix() + global MRIToolkit; + download_url = ''; + if(ispc) + download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-win64.zip'; + elseif(ismac) + download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-mac.zip'; + elseif(isunix) + download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-linux.zip'; + end + dest_folder = userpath; + if(isempty(dest_folder)) + dest_folder = MRIToolkit.RootFolder; + end + urlwrite (download_url, fullfile(dest_folder,'Elastix.zip')); + unzip(fullfile(dest_folder,'Elastix.zip'),fullfile(dest_folder,'Elastix')); + delete(fullfile(dest_folder,'Elastix.zip')); + if(ismac || isunix) + system(['mv ' fullfile(dest_folder,'Elastix','bin','*') ' ' fullfile(dest_folder,'Elastix')]); + system(['mv ' fullfile(dest_folder,'Elastix','lib','*') ' ' fullfile(dest_folder,'Elastix')]); + system(['chmod +x ' fullfile(dest_folder,'Elastix','elastix')]); + system(['chmod +x ' fullfile(dest_folder,'Elastix','transformix')]); + end + + MRIToolkitGetSetVars('MRIToolkit.Elastix.Location',fullfile(dest_folder,'Elastix')); + MRIToolkit.Elastix.Location = fullfile(dest_folder,'Elastix'); + MRIToolkit.Elastix.ElastixCMD = fullfile(MRIToolkit.Elastix.Location,'elastix'); + MRIToolkit.Elastix.TransformixCMD = fullfile(MRIToolkit.Elastix.Location,'transformix'); + end + + end +end \ No newline at end of file diff --git a/ImageRegistrations/mk_init.asv b/ImageRegistrations/mk_init.asv new file mode 100644 index 0000000..c392445 --- /dev/null +++ b/ImageRegistrations/mk_init.asv @@ -0,0 +1,71 @@ +%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%% +%%% Alberto De Luca - alberto@isi.uu.nl $%%% +%%% Distributed under the terms of LGPLv3 %%% + + + +% A. De Luca +% Sub-toolbox specific initialization +% 29/03/2018: creation - v1.0 +global MRIToolkit; +MRIToolkit.image_registrations_version = 1.1; + +addpath(get_executed_file_path()) +addpath(fullfile(get_executed_file_path(),'elastix_parameters')) + +MRIToolkit.Elastix.Works = false; +try + if(~isfield(MRIToolkit.Elastix,'Location') || exist(MRIToolkit.Elastix.Location,'dir') < 1) + if(exist(fullfile(userpath,'Elastix'),'dir') > 0) + MRIToolkit.Elastix.Location = fullfile(userpath,'Elastix'); + MRIToolkit.Elastix.ElastixCMD = fullfile(userpath,'Elastix','elastix'); + MRIToolkit.Elastix.TransformixCMD = fullfile(userpath,'Elastix','transformix'); + else + MRIToolkit.Elastix.Location = ''; + end + end + if(exist(MRIToolkit.Elastix.Location,'dir') > 0) + if(exist(MRIToolkit.Elastix.ElastixCMD,'file') > 0 && exist(MRIToolkit.Elastix.TransformixCMD,'file') > 0) + [a,b] = system(MRIToolkit.Elastix.ElastixCMD); + [c,d] = system(MRIToolkit.Elastix.TransformixCMD); + if(contains(b,'elastix-usage') > 0 && contains(d,'transformix-usage') > 0) + MRIToolkit.Elastix.Works = true; + end + end + end + if(MRIToolkit.Elastix.Works == false) + warning('There seems to be a problem with the installation of Elastix. Do you want me to attempt fixing it by downloading elastix in your home folder?'); + answer = input('Answer yes/no: ',"s"); + if(strcmpi(answer,'yes')) + download_url = ''; + if(ispc) + download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-win64.zip'; + elseif(ismac) + download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-mac.zip'; + elseif(isunix) + download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-linux.zip'; + end + urlwrite (download_url, fullfile(userpath,'Elastix.zip')); + unzip(fullfile(userpath,'Elastix.zip'),fullfile(userpath,'Elastix')); + delete(fullfile(userpath,'Elastix.zip')); + if(ismac || isunix) + system(['mv ' fullfile(userpath,'Elastix','bin','*') ' ' fullfile(userpath,'Elastix')]); + system(['mv ' fullfile(userpath,'Elastix','lib','*') ' ' fullfile(userpath,'Elastix')]); + end + dest_folder = userpath; + if(isempty(dest_folder)) + dest_folder = fullfile(MRIToolkit.RootFolder,'Elastix'); + else + dest_folder = fullfile(dest_folder,'Elastix'); + mkdir(dest_folder); + end + MRIToolkitGetSetVars('MRIToolkit.Elastix.Location',dest_folder); + MRIToolkit.Elastix.Location = dest_folder; + MRIToolkit.Elastix.ElastixCMD = fullfile(dest_folder,'elastix'); + MRIToolkit.Elastix.TransformixCMD = fullfile(dest_folder,'transformix'); + else + warning('Motion correction and image registrations will not work until Elastix is properly configured.'); + end + end +catch +end diff --git a/ImageRegistrations/mk_init.m b/ImageRegistrations/mk_init.m index e3009cf..3f5c456 100644 --- a/ImageRegistrations/mk_init.m +++ b/ImageRegistrations/mk_init.m @@ -1 +1 @@ -%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%% %%% Alberto De Luca - alberto@isi.uu.nl $%%% %%% Distributed under the terms of LGPLv3 %%% % A. De Luca % Sub-toolbox specific initialization % 29/03/2018: creation - v1.0 global MRIToolkit; MRIToolkit.image_registrations_version = 1.0; addpath(get_executed_file_path()) addpath(fullfile(get_executed_file_path(),'elastix_parameters')) MRIToolkit.Elastix.Works = false; try if(~isfield(MRIToolkit.Elastix,'Location') || exist(MRIToolkit.Elastix.Location,'dir') < 1) if(exist(fullfile(userpath,'Elastix'),'dir') > 0) MRIToolkit.Elastix.Location = fullfile(userpath,'Elastix'); MRIToolkit.Elastix.ElastixCMD = fullfile(userpath,'Elastix','elastix'); MRIToolkit.Elastix.TransformixCMD = fullfile(userpath,'Elastix','transformix'); else MRIToolkit.Elastix.Location = ''; end end if(exist(MRIToolkit.Elastix.Location,'dir') > 0) if(exist(MRIToolkit.Elastix.ElastixCMD,'file') > 0 && exist(MRIToolkit.Elastix.TransformixCMD,'file') > 0) [a,b] = system(MRIToolkit.Elastix.ElastixCMD); [c,d] = system(MRIToolkit.Elastix.TransformixCMD); if(contains(b,'elastix-usage') > 0 && contains(d,'transformix-usage') > 0) MRIToolkit.Elastix.Works = true; end end end if(MRIToolkit.Elastix.Works == false) warning('There seems to be a problem with the installation of Elastix. Do you want me to attempt fixing it by downloading elastix in your home folder?'); answer = input('Answer yes/no: ',"s"); if(strcmpi(answer,'yes')) download_url = ''; if(ispc) download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-win64.zip'; elseif(ismac) download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-mac.zip'; elseif(isunix) download_url = 'https://github.com/SuperElastix/elastix/releases/download/5.1.0/elastix-5.1.0-linux.zip'; end urlwrite (download_url, fullfile(userpath,'Elastix.zip')); unzip(fullfile(userpath,'Elastix.zip'),fullfile(userpath,'Elastix')); delete(fullfile(userpath,'Elastix.zip')); if(ismac || isunix) system(['mv ' fullfile(userpath,'Elastix','bin','*') ' ' fullfile(userpath,'Elastix')]); system(['mv ' fullfile(userpath,'Elastix','lib','*') ' ' fullfile(userpath,'Elastix')]); end MRIToolkitGetSetVars('MRIToolkit.Elastix.Location',MRIToolkit.Elastix.Location); MRIToolkit.Elastix.Location = MRIToolkit.Elastix.Location; MRIToolkit.Elastix.ElastixCMD = fullfile(userpath,'Elastix','elastix'); MRIToolkit.Elastix.TransformixCMD = fullfile(userpath,'Elastix','transformix'); else warning('Motion correction and image registrations will not work until Elastix is properly configured.'); end end catch end \ No newline at end of file +%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%% %%% Alberto De Luca - alberto@isi.uu.nl $%%% %%% Distributed under the terms of LGPLv3 %%% % A. De Luca % Sub-toolbox specific initialization % 29/03/2018: creation - v1.0 global MRIToolkit; MRIToolkit.image_registrations_version = 1.1; addpath(get_executed_file_path()) addpath(fullfile(get_executed_file_path(),'elastix_parameters')) MRIToolkit.Elastix.Works = false; try if(~isfield(MRIToolkit.Elastix,'Location') || exist(MRIToolkit.Elastix.Location,'dir') < 1) if(exist(fullfile(userpath,'Elastix'),'dir') > 0) MRIToolkit.Elastix.Location = fullfile(userpath,'Elastix'); MRIToolkit.Elastix.ElastixCMD = fullfile(userpath,'Elastix','elastix'); MRIToolkit.Elastix.TransformixCMD = fullfile(userpath,'Elastix','transformix'); else MRIToolkit.Elastix.Location = ''; end end if(exist(MRIToolkit.Elastix.Location,'dir') > 0) if(exist(MRIToolkit.Elastix.ElastixCMD,'file') > 0 && exist(MRIToolkit.Elastix.TransformixCMD,'file') > 0) [a,b] = system(ImageRegistrations.BasicElastixCall()); [c,d] = system(ImageRegistrations.BasicTransformixCall()); if(contains(b,'elastix-usage') > 0 && contains(d,'transformix-usage') > 0) MRIToolkit.Elastix.Works = true; end end end if(MRIToolkit.Elastix.Works == false) warning('There seems to be a problem with the installation of Elastix. I can attempt fixing it by downloading elastix in your home folder. Call ImageRegistrations.DownloadElastix() to do so.'); warning('Motion correction and image registrations will not work until Elastix is properly configured.'); end catch end \ No newline at end of file diff --git a/MRIToolkitInit.m b/MRIToolkitInit.m index 994f484..ac9d662 100644 --- a/MRIToolkitInit.m +++ b/MRIToolkitInit.m @@ -60,7 +60,8 @@ function MRIToolkitInit(SelectedToolboxes) end run_folder = get_executed_file_path(); - + MRIToolkit.RootFolder = run_folder; + % Add all toolboxes if no input is specified if(nargin < 1) SelectedToolboxes = available_toolboxes;