Print

Print


Two quick comments:

(1) You should be very careful using the recursive script. Removing the old files will break functions that look at the SPM.mat for the filenames.

(2) There are two types of nifti files, the data and headers are identical in both. One type comes in an img/hdr pair and the other comes as a single .nii file.

Best Regards, Donald McLaren
=================
D.G. McLaren, Ph.D.
Postdoctoral Research Fellow, GRECC, Bedford VA
Research Fellow, Department of Neurology, Massachusetts General Hospital and
Harvard Medical School
Office: (773) 406-2464
=====================
This e-mail contains CONFIDENTIAL INFORMATION which may contain PROTECTED
HEALTHCARE INFORMATION and may also be LEGALLY PRIVILEGED and which is
intended only for the use of the individual or entity named above. If the
reader of the e-mail is not the intended recipient or the employee or agent
responsible for delivering it to the intended recipient, you are hereby
notified that you are in possession of confidential and privileged
information. Any unauthorized use, disclosure, copying or the taking of any
action in reliance on the contents of this information is strictly
prohibited and may be unlawful. If you have received this e-mail
unintentionally, please immediately notify the sender via telephone at (773)
406-2464 or email.



On Sun, Nov 20, 2011 at 10:14 AM, Alejandro Vicente Grabovetsky <[log in to unmask]> wrote:
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

function img2niiRC(rtDir)

if nargin == 0
   rtDir = '.';
end

% Get the absolute path of directory...
here = pwd;
cd(rtDir)
rtDir = pwd;
cd(here)

% 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...
while ~isempty(fldrDir)
   [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']);
       spm_write_vol(V, Y);
       % Remove old file
       unix(['rm ' fullfile(rt,[nm ext])]);
       unix(['rm ' fullfile(rt,[nm '.hdr'])]);
   end
end

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
> fslchfiletype.
>
> Hope this helps!
>
> Best regards,
>
> Jonathan
>
> --
> Dr. Jonathan Peelle
> Department of Neurology
> University of Pennsylvania
> 3 West Gates
> 3400 Spruce Street
> Philadelphia, PA 19104
> USA
> http://jonathanpeelle.net/