% *****************************************************
%
% SPM12 batch code
%
%function call: matlab -nodisplay -nosplash -nodesktop -nojvm -r "deformBack('rT1.nii', 'y_rT1.nii'); quit"
% *****************************************************

function deformBack(defField, structures)

    clc;
    spm_jobman('initcfg');

    matlabbatch{1}.spm.util.defs.comp{1}.def = {defField};
    matlabbatch{1}.spm.util.defs.out{1}.pull.fnames = {structures};
    matlabbatch{1}.spm.util.defs.out{1}.pull.savedir.savepwd = 1;
    matlabbatch{1}.spm.util.defs.out{1}.pull.interp = 0;
    matlabbatch{1}.spm.util.defs.out{1}.pull.mask = 1;
    matlabbatch{1}.spm.util.defs.out{1}.pull.fwhm = [0 0 0];
    
    spm('defaults','pet');    
    spm_jobman('run',matlabbatch);    
    spm_clf;
    clear matlabbatch;

end