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

function regSingle(target, source)

    clc;
    spm_jobman('initcfg');

    matlabbatch{1}.spm.spatial.coreg.estwrite.ref = {[target, ',1']};
    matlabbatch{1}.spm.spatial.coreg.estwrite.source = {[source, ',1']};
    matlabbatch{1}.spm.spatial.coreg.estwrite.eoptions.cost_fun = 'nmi';
    matlabbatch{1}.spm.spatial.coreg.estwrite.eoptions.sep = [4 2];
    matlabbatch{1}.spm.spatial.coreg.estwrite.eoptions.tol = [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
    matlabbatch{1}.spm.spatial.coreg.estwrite.eoptions.fwhm = [7 7];
    matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.interp = 7;
    matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.wrap = [0 0 0];
    matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.mask = 0;
    matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.prefix = 'r';
    
    spm('defaults','pet');    
    spm_jobman('run',matlabbatch);    
    spm_clf;
    clear matlabbatch;

end

