-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Can automatically download Elastix if needed from GitHub
- Loading branch information
Showing
10 changed files
with
196 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
!.gitignore | ||
|
||
.DS_Store | ||
Elastix | ||
MRIToolkitDefineLocalVars.m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
%%% Alberto De Luca - [email protected] $%%% | ||
%%% Distributed under the terms of LGPLv3 %%% | ||
|
||
|
||
|
||
function DW_Elastix_Register(moving,fixed,regparlist,output_dir,mMask,fMask,outfilename) | ||
global MRIToolkit; | ||
if(isfield(MRIToolkit,'Elastix')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
%%% Alberto De Luca - [email protected] $%%% | ||
%%% Distributed under the terms of LGPLv3 %%% | ||
|
||
|
||
|
||
function DW_Elastix_Transform(filein,fileout,transform_parameters) | ||
global MRIToolkit; | ||
if(isfield(MRIToolkit,'Elastix')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%% | ||
%%% Alberto De Luca - [email protected] $%%% | ||
%%% 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%% | ||
%%% Alberto De Luca - [email protected] $%%% | ||
%%% 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%%%%% Alberto De Luca - [email protected] $%%%%%% Distributed under the terms of LGPLv3 %%%% A. De Luca% Sub-toolbox specific initialization% 29/03/2018: creation - v1.0global 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 endcatchend | ||
%%%$ Included in MRIToolkit (https://github.com/delucaal/MRIToolkit) %%%%%% Alberto De Luca - [email protected] $%%%%%% Distributed under the terms of LGPLv3 %%%% A. De Luca% Sub-toolbox specific initialization% 29/03/2018: creation - v1.0global 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.'); endcatchend | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters