function ofNm = zeronan(ifNm) % FORMAT ofNm = zeronan(ifNm) % ifNm - Input filename(s) % % Output: % ofNm - Cell array of output filenames. % % % Images have NaN's replaced with zeros, and new images, prefixed with a % 'z', are created. % %________________________________________________________________________ % @(#)zeronan.m 1.1 T. Nichols 02/08/21 if ~iscell(ifNm) ifNm = cellstr(ifNm)'; else ifNm = ifNm(:)'; end OtfNm = {}; for fNm = ifNm fNm = fNm{:}; OfNm = ['z' fNm]; [pth,nm,xt] = fileparts(fNm); OfNm = fullfile(pth,['z' nm xt]); % Code snippet from John Ashburner... VI = spm_vol(fNm); VO = VI; VO.fname = OfNm; VO = spm_create_image(VO); for i=1:VI.dim(3), img = spm_slice_vol(VI,spm_matrix([0 0 i]),VI.dim(1:2),0); tmp = find(isnan(img)); img(tmp) = 0; VO = spm_write_plane(VO,img,i); end; OtfNm = {OtfNm{:} OfNm}; end if nargout>0 ofNm = OtfNm; end