help > RE: mriCRON: Nifti to .hdr
Apr 26, 2021  11:04 AM | Chris Rorden
RE: mriCRON: Nifti to .hdr
Modern SPM works well with single file NIfTI (filename.nii), so I am not sure why you need the dual file version (.hdr/.img). I have moved active development to MRIcroGL, so the MRIcron documentation might be getting a bit out of date.

I would use the FSL tool fslchfiletype to do this, but you could also use a Matlab script with SPM:



function nii_nii2hdr (fnms)
%Convert file.nii to file.hdr/file.img
% https://github.com/rordenlab/dcm2niix/is...
%n.b. FSL does not like file.nii and file.hdr co-existing
% fnms : (optional) images to convert
%Examples
% nii_nii2hdr
% nii_nii2hdr('T1_LM1003.nii');
% nii_nii2hdr(strvcat('T1_LM1003.nii','T2_LM1003.nii'));

if ~exist('fnms','var') %file not specified
[A,Apth] = uigetfile({'*.nii';'*.*'},'Select .nii file(s)', 'MultiSelect', 'on');
fnms = strcat(Apth,char(A));
end
for i=1:size(fnms,1)
fnm = fnms(i,:);
[pth, nm] = spm_fileparts(fnm);
hdr = spm_vol(fnm);
img = spm_read_vols(hdr);
hdr.fname = fullfile(pth, [nm, '.img']);
spm_write_vol(hdr,img);
end

Threaded View

TitleAuthorDate
rosenkohl Apr 26, 2021
RE: mriCRON: Nifti to .hdr
Chris Rorden Apr 26, 2021
rosenkohl Apr 26, 2021