I think I figures it out! The header I was using was the header of one of the binary mask images. I found (through experience) that if you want to write a volume with non-discrete values, you should use the header from say a file that takes non-discrete values (e.g. a beta file). Now the maximum difference is in the order of 1e-7... Hamed On Sun, Jul 17, 2016 at 1:40 PM, hamed nili <[log in to unmask]> wrote: > Dear all, > > I am using spm12 for some of my analysis. I create images in subject's > native space and firstly want to write them as Nifti images. So I use > spm_write_vol. It's strange that the nifti image that I write is not the > same as the image that I feed in the function! > > Can anyone point out the mistake I am making or the solution they have. > Here is the code: > > V = spm_vol(binaryMaskFile);% binaryMaskFile is one of the subject's > files, e.g. their mask.nii created after the first level stats > > % now I change the name of the file > > V.fname = 'test.nii'; > > % generate random data > > data = randn(96,96,72); > > % save it > > spm_write_vol(V,data); > > % read in the written volume and find the difference > > diffVol = spm_read_vols(spm_vol('test.nii')) - data; > > max(diffVol(:)) % I get 4.4715 in one example > > > >