Skip to content

Commit

Permalink
Allow to build upon preexisting ANTs warps.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashorn committed Dec 29, 2018
1 parent bc498c6 commit 68a2280
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
Binary file modified common/ea_prefs_default.mat
Binary file not shown.
Binary file modified ea_normsettings_ants.fig
Binary file not shown.
30 changes: 29 additions & 1 deletion ea_normsettings_ants.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

% Edit the above text to modify the response to help ea_normsettings_ants

% Last Modified by GUIDE v2.5 02-Dec-2018 14:34:00
% Last Modified by GUIDE v2.5 29-Dec-2018 11:48:39

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
Expand Down Expand Up @@ -114,6 +114,9 @@ function ea_normsettings_ants_OpeningFcn(hObject, eventdata, handles, varargin)

set(handles.skullstripped,'Value',prefs.machine.normsettings.ants_skullstripped);

set(handles.usepreexisting,'Value',prefs.machine.normsettings.ants_usepreexisting);


% UIWAIT makes ea_normsettings_ants wait for user response (see UIRESUME)


Expand Down Expand Up @@ -179,6 +182,8 @@ function savebutn_Callback(hObject, eventdata, handles)

normsettings.ants_reinforcetargets=get(handles.reinforcetargets,'Value');

normsettings.ants_usepreexisting=get(handles.usepreexisting,'Value');


if get(handles.restrcores,'Value')
normsettings.ants_numcores=get(handles.numcores,'String');
Expand Down Expand Up @@ -317,3 +322,26 @@ function reinforcetargets_Callback(hObject, eventdata, handles)
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of reinforcetargets


% --- Executes on selection change in usepreexisting.
function usepreexisting_Callback(hObject, eventdata, handles)
% hObject handle to usepreexisting (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns usepreexisting contents as cell array
% contents{get(hObject,'Value')} returns selected item from usepreexisting


% --- Executes during object creation, after setting all properties.
function usepreexisting_CreateFcn(hObject, eventdata, handles)
% hObject handle to usepreexisting (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
17 changes: 9 additions & 8 deletions ext_libs/ANTs/ea_ants_nonlinear.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ function ea_ants_nonlinear(varargin)
end


rigidstage = [' --initial-moving-transform [', fixedimage{1}, ',', movingimage{1}, ',0]' ...
' --transform Rigid[0.25]' ... % bit faster gradient step (see https://github.com/stnava/ANTs/wiki/Anatomy-of-an-antsRegistration-call)
rigidstage = [' --transform Rigid[0.25]' ... % bit faster gradient step (see https://github.com/stnava/ANTs/wiki/Anatomy-of-an-antsRegistration-call)
' --convergence ', rigidconvergence, ...
' --shrink-factors ', rigidshrinkfactors, ...
' --smoothing-sigmas ', rigidsmoothingssigmas, ...
Expand Down Expand Up @@ -289,6 +288,8 @@ function ea_ants_nonlinear(varargin)
setenv('ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS',options.prefs.machine.normsettings.ants_numcores) % no num2str needed since stored as string.
end

props.moving = movingimage{1};
props.fixed = fixedimage{1};
props.outputbase = outputbase;
props.ANTS = ANTS;
props.outputimage = outputimage;
Expand All @@ -299,12 +300,12 @@ function ea_ants_nonlinear(varargin)
props.synmaskstage = synmaskstage;
props.directory = directory;
props.stagesep = options.prefs.machine.normsettings.ants_stagesep;
if exist([fileparts(movingimage{1}),filesep,'glanatComposite.h5'],'file')
% clean old deformation field. this is important for cases where ANTs
% crashes and the user does not get an error back. Then, preexistant old transforms
% will be considered as new ones.
delete([fileparts(movingimage{1}),filesep,'glanatComposite.h5']);
end
% if exist([fileparts(movingimage{1}),filesep,'glanatComposite.h5'],'file')
% % clean old deformation field. this is important for cases where ANTs
% % crashes and the user does not get an error back. Then, preexistant old transforms
% % will be considered as new ones.
% delete([fileparts(movingimage{1}),filesep,'glanatComposite.h5']);
% end
ea_submit_ants_nonlinear(props);

if exist('tmaskdir','var')
Expand Down
29 changes: 29 additions & 0 deletions ext_libs/ANTs/ea_submit_ants_nonlinear.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ function ea_submit_ants_nonlinear(props)


function ea_antsnl_monostep(props)
directory=fileparts(props.moving);
directory=[directory,filesep];
if exist([fileparts(props.moving),filesep,'glanatComposite',ea_getantstransformext(directory)],'file') % prior ANTs transform found.
prefs=ea_prefs;
switch prefs.machine.normsettings.ants_usepreexisting
case 1 % ask
answ=questdlg('We found an old ANTs transform file. Do you wish to reuse the transform or discard the old one?','Old ANTs transform found.','Reuse','Discard','Discard');
switch lower(answ)
case 'reuse'
initreg=[' --initial-moving-transform ',ea_path_helper([fileparts(props.moving),filesep,'glanatComposite',ea_getantstransformext(directory)])];
props.rigidstage='';
props.affinestage='';
case 'discard'
ea_delete([fileparts(props.moving),filesep,'glanatComposite',ea_getantstransformext(directory)])
initreg=[' --initial-moving-transform [', props.fixed, ',', props.moving, ',0]'];
end
case 2 % reuse
initreg=[' --initial-moving-transform ',ea_path_helper([fileparts(props.moving),filesep,'glanatComposite',ea_getantstransformext(directory)])];
props.rigidstage='';
props.affinestage='';
case 3 % overwrite
% clean old deformation field. this is important for cases where ANTs
% crashes and the user does not get an error back. Then, preexistant old transforms
% will be considered as new ones.
ea_delete([fileparts(props.moving),filesep,'glanatComposite',ea_getantstransformext(directory)])
initreg=[' --initial-moving-transform [', props.fixed, ',', props.moving, ',0]'];
end
end

cmd = [props.ANTS, ' --verbose 1', ...
' --dimensionality 3', ...
Expand All @@ -17,6 +45,7 @@ function ea_antsnl_monostep(props)
' --float 1',...
' --winsorize-image-intensities [0.005,0.995]', ...
' --write-composite-transform 1', ...
initreg, ...
props.rigidstage, props.affinestage, props.synstage, props.slabstage, props.synmaskstage];

fid = fopen([props.directory,'ea_ants_command.txt'],'a');
Expand Down

0 comments on commit 68a2280

Please sign in to comment.