You could transform all images to niftis in batch using something like this (WARNING: this particular script deletes the img and hdr files afterwards...)
% This is a recursive form of img2nii that lists all the img's inside a
% folder and its subfolders, and then converts them into nii's
if nargin == 0
rtDir = '.';
% Get the absolute path of directory...
here = pwd;
rtDir = pwd;
% We get the path inside the folders in the rtDir
fldrDir = genpath(rtDir);
% Then recurse through the string, listing all files and folders, and
% converting them...
[fldrCurr fldrDir] = strtok(fldrDir, ':');
fileDir = dir(fullfile(fldrCurr, '*.img'));
fprintf('\nDealing with folder %s, containing %.0f images', fldrCurr, length(fileDir))
for f = 1:length(fileDir)
% Load img file
V = spm_vol(fullfile(fldrCurr, fileDir(f).name));
Y = spm_read_vols(V);
% Write nii file
[rt, nm, ext] = fileparts(V.fname);
V.fname = fullfile(rt, [nm '.nii']);
% Remove old file
unix(['rm ' fullfile(rt,[nm ext])]);
unix(['rm ' fullfile(rt,[nm '.hdr'])]);
On 20 Nov 2011, at 13:34, Jonathan Peelle wrote:
> Dear Debby,
>> However, the result of SPM is a .hdr and a .img file. I would like to have a nifti file as output from the SPM analysis, preferably a mask with the voxels that are activated (under certain FDR constraints) white, and the rest black (or the other way around). I tried to read the resulting .hdr file into MRIcro and then save it as a Nifti, but the disadvantage is that you have to threshold the file yourself in MRIcro and I don't know the conversion between the FDR=0.05 threshold in SPM and the thresholds used in MRIcro. So it would be much easier if I can get this .nii file immediately out of SPM...
> First, to save any threshold image (e.g., one that is thresholded at
> FDR<.05), simply click the "save" button once you've gotten your
> results. This allows you to specify any filename, and will only
> provide values for the voxels showing on your glass brain.
> If you would like to transform this into a binary image, you can do so
> using ImCalcójust select this thresholded image, and specify a formula
> of "i1>0", and you should get what you need. Incidentally, in ImCalc,
> if you specify a ".nii" extension to the output image, you will get a
> single-file Nifti image, so then you'd be done.
> If you ever want to convert img/hdr Nifti files that SPM produces to
> single-image Nifti files, you can do this easily using the FSL utility
> Hope this helps!
> Best regards,
> Dr. Jonathan Peelle
> Department of Neurology
> University of Pennsylvania
> 3 West Gates
> 3400 Spruce Street
> Philadelphia, PA 19104