Print

Print


Thanks for the reply, Donald.

And just for completeness for others who are looking, this is the code to convert from mm (in whatever space your images are in e.g. MNI if images are normalized to MNI space) to voxel coordinates (where 1st voxel is at (1,1,1) bottom right)

Vhdr = spm_vol(conImg);    % use spm_vol to get con img header
V = spm_read_vols(Vhdr);  % actual data for later
M            = Vhdr.mat;             % 4x4 affine transform matrix for voxel coords to mm coords
iM           = inv(M);                  % inverse transform for mm to voxel coords 

% (xm ym zm) = mm coords
% xyz0 gives voxel coords
xyz0 = iM*[xm ym zm 1]'