Print

Print


> I am trying to write a program in Matlab that processes a series of images
> in Analyze format, and writes the output as Analyze images.  While I could
> create the .img files without any problems, I was having a harder time
> creating the .hdr files.  I decided to use SPM functions to help me for
> this step.
>
> I do have SPM installed, and am trying to use its functions to help me
> create the header file.  I was able to run the following example:
>
> % The volume that I wish to output
> Volume = zeros(30,30,30);
>
> Info.mat=[2 0 0 0; 0 2 0 0; 0 0 2 0; 0 0 0 1]
> Info.fname    = 'foobar.img';
> Info.dim = [30,30,30,2];
>
> spm_write_vol(Info,Volume)
>
> However, I think I am doing something incorrectly, as I encounter the
> following warnings multiple times.  Is there something I should be doing
> differently?
>
> Warning: Cant get default Analyze orientation - assuming flipped
>
> > In spm_flip_analyze_images at 9


Try running
>>  spm_defaults
first.  SPM allows a site to have their data stored as left-handed (most 
people, and the official Analyze orientation) or right-handed.  The 
preference is saved in spm_defaults.m.  In order to determine the site 
preference, the spm_defaults.m file must first be executed (normally done 
when you type spm).


> Moreover, I'm confused by how to set up the affine transformation matrix.
> I'm trying to set up spacing to be 2mm x 2mm x 2mm.  However, the resulting
> x spacing is -2.  Why would this be occurring?

The default is to have left-handed storage, whereas Neurologists prefer to 
view their co-ordinates as right-handed (e.g. the T&T atlas).  The flip in 
the x direction is so that locations within the .img file (assumed to be 
left-handed storage) can be interpreted within a right-handed coordinate 
system.  You may want to take a look at the spm_get_space.m routine for more 
information about how the transform could be generated.

>
> Also, could someone please explain the meaning of the of Info.dim?  What is
> the meaning of dim[3]?  I managed to get this to work by trial error, but
> would prefer to understand what is happening here.

Do you mean dim[4]?  In SPM2, this is the datatype.  See spm_type for more 
information.  dim[3] is simply the number of slices in the file.

Best regards,
-John