Print

Print


I don't have a stylized, compact answer, but here's what the help for spm_vol says for one of the SPM8 versions:

-------------begin--------------------

>> help spm_vol
  Get header information etc for images.
  FORMAT V = spm_vol(P)
  P - a matrix of filenames.
  V - a vector of structures containing image volume information.
  The elements of the structures are:
        V.fname - the filename of the image.
        V.dim   - the x, y and z dimensions of the volume
        V.dt    - A 1x2 array.  First element is datatype (see spm_type).
                  The second is 1 or 0 depending on the endian-ness.
        V.mat   - a 4x4 affine transformation matrix mapping from
                  voxel coordinates to real world coordinates.
        V.pinfo - plane info for each plane of the volume.
               V.pinfo(1,:) - scale for each plane
               V.pinfo(2,:) - offset for each plane
                  The true voxel intensities of the jth image are given
                  by: val*V.pinfo(1,j) + V.pinfo(2,j)
               V.pinfo(3,:) - offset into image (in bytes).
                  If the size of pinfo is 3x1, then the volume is assumed
                  to be contiguous and each plane has the same scalefactor
                  and offset.
 __________________________________________________________________________
 
  The fields listed above are essential for the mex routines, but other
  fields can also be incorporated into the structure.
 
  The images are not memory mapped at this step, but are mapped when
  the mex routines using the volume information are called.
 
  Note that spm_vol can also be applied to the filename(s) of 4-dim
  volumes. In that case, the elements of V will point to a series of 3-dim
  images.
 _______________________________________________________________________
  Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

-----------------end---------------------------------------

Assuming by "spacing" you mean the size of a single voxel in mm, then
    V.dim
isn't what you want.  Rather, that's the dimensions of the bounding box, in voxels.

V.mat is the "voxel to mm" transformation.  It's a 4x4 matrix.  If the upper-left 3x3 submatrix is diagonal, you can read the voxel size in mm easily.  For example, I just applied spm_vol to "beta" image I have, and got


V.mat = ...
    -2     0     0    80
     0     2     0  -114
     0     0     2   -52
     0     0     0     1

So in this case the voxel is (in mm) of size 2, 2, and 2.

If it's not diagonal, you could figure it out by hand using some elementary math.  Or I think you could use this line:
    P = spm_imatrix(V.mat);

In the above case, we get
    P = [80  -114   -52     0     0     0    -2     2     2     0     0     0]

To isolate the voxel size, use
    abs(P(7:9))

The documentation behind 7:9:  "help spm_imatrix" sends you to spm_matrix (basically, the inverse transformation); "help spm_matrix" says:

-------------begin--------------------

>> help spm_matrix
  returns an affine transformation matrix
  FORMAT [A] = spm_matrix(P, order)
  P(1)  - x translation
  P(2)  - y translation
  P(3)  - z translation
  P(4)  - x rotation about - {pitch} (radians)
  P(5)  - y rotation about - {roll}  (radians)
  P(6)  - z rotation about - {yaw}   (radians)
  P(7)  - x scaling
  P(8)  - y scaling
  P(9)  - z scaling
  P(10) - x affine
  P(11) - y affine
  P(12) - z affine

-----------------end---------------------------------------

So:  P(1:6) is just solid body motion stuff.  P(7), P(8), P(9) clearly tell you the size in mm of a cube that's 1x1x1 in voxel units, which is what you want.

If any of P(10:12) are nonzero, then the voxels are "sheared", and aren't "rectangular" boxes anymore, so the dimensions of the voxel would no longer be a complete description of its shape.  Usually there's no shearing, though.