Fraser Smith wrote:
> If I read an image into a matrix A, using spm_read_vols, I get an
> XbyYbyZ image, plus a set of XYZ locations returned.
> My question is, how exactly do the locations correspond to the
> individual voxels in the the XbyYbyZ image?
Hi Fraser,
The rows of the XYZ matrix are x,y,z (world) coordinates in mm, the
columns correspond to the voxels in Matlab's linear-indexing
convention (i.e. fastest changing dimension down the columns, then
along the rows, then through planes slowest changing dimension).
The following might clarify this:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
V = spm_vol('image.img');
[img XYZ] = spm_read_vols(V);
vox = 12345; % 12345th voxel (linear index)
% convert from linear index to subscripts
[x y z] = ind2sub(size(img), vox);
XYZ(:, vox) % world coords at voxel vox
V.mat*[x y z 1]' % same at voxel (x,y,z)
% note that vox and (x,y,z) refer to the same voxel:
img(x,y,z)
img(vox)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Personally, I find the V.mat*[x y z 1]' method of getting world
coordinates at voxel (x,y,z) easier than using linear indexing into
the XYZ variable anyway.
Best,
Ged.
|