function myspm_invnormalise_spm12(image_to_be_normalised,def,reference)
    

% image_to_be_normalised =roi;
% def=sn_matname;

    matlabbatch{1}.spm.spatial.normalise.write.subj.def{1} = def;
    matlabbatch{1}.spm.spatial.normalise.write.subj.resample{1} = image_to_be_normalised;
    matlabbatch{1}.spm.spatial.normalise.write.woptions.bb = [NaN NaN NaN;NaN NaN NaN];
    matlabbatch{1}.spm.spatial.normalise.write.woptions.vox = [NaN NaN NaN];
    matlabbatch{1}.spm.spatial.normalise.write.woptions.interp = 4;
    
    matlabbatch{2}.spm.spatial.realign.write.data{1} = reference;
    [p,f,e]=fileparts(image_to_be_normalised);
    matlabbatch{2}.spm.spatial.realign.write.data{2} = fullfile(p,sprintf('w%s%s',f,e));
   % matlabbatch{2}.spm.spatial.realign.write.data{2} = fullfile(p,sprintf('%s%s',f,e));
    matlabbatch{2}.spm.spatial.realign.write.data = matlabbatch{2}.spm.spatial.realign.write.data';
    matlabbatch{2}.spm.spatial.realign.write.roptions.which = [2 1];
    matlabbatch{2}.spm.spatial.realign.write.roptions.interp = 4;
    matlabbatch{2}.spm.spatial.realign.write.roptions.wrap = [0 0 0];
    matlabbatch{2}.spm.spatial.realign.write.roptions.mask = 1;
    matlabbatch{2}.spm.spatial.realign.write.roptions.prefix = 'r';

    spm('defaults', 'FMRI');
    spm_jobman('serial', matlabbatch);    
    
end




