Dear Yune,
I am using John's spm_get_space to do this. A script using this function
is attached. This script has been written to work with Analyze-Files - I
haven't checked it with nifti files, but think, it should be okay.
Its usage is:
vox = mm2vox( mm, fname);
with "mm" being a n x 3 matrix of MNI coordinates
and "filename" being the filename of an image defining the voxel space
(e.g. the MNI template, or the image containing whatever voxel matrix
you would like to select voxels from)
alternative usage:
vox = mm2vox( mm, V);
with "V" being the result of spm_vol(fname)
Note that the resulting [n x 3] list of voxel coordinates includes
fractional values. If you want to use them to index a matrix, you should
probably use
vox = round(mm2vox( mm, fname));
hope it works for you - otherwise let me know.
Cheers,
Kai
Yune Lee wrote:
> Dear SPM users,
>
> I'm trying to figure out the corresponding matlab matrix of a large
> number of MNI coordinate and wondering if there is any way to
> do it quickly.
> If anyone already have the script and is willing to share it, I would
> really appreciate.
>
> Thanks,
> YSL
--
Dr. Kai Lutz
Neuropsychology
Institute for Psychology
University of Zurich
Binzmühlestrasse 14 /Box 25
CH-8050 Zürich
Switzerland
_________________________
Diese E-Mail (ggf. nebst Anhang) enthält vertrauliche und/oder rechtlich
geschützte Informationen. Wenn Sie nicht der richtige Adressat sind, oder
diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die
unbefugte Weitergabe dieser Mail ist nicht gestattet.
This e-mail (and any attachment/s) contains confidential and/or privileged
information. If you are not the intended recipient (or have received this
e-mail in error) please notify the sender immediately and destroy this
e-mail. Any unauthorised copying, disclosure or distribution of the
material in this e-mail is strictly forbidden.
_________________________
function vox=mm2vox(varargin)
% function vox=mm2vox(mm, V)
%
% converts mm-coordinates in voxel-coordinates/indices
% using an existing transformation matrix
% vox = [x, y, z] voxel coordinates
% mm = [x y z] mm coordinates
% V = structure containing Image information (e.g., use the MNI template) -
% (see spm_vol)
% uses spm_get_space.m by John Ashburner
%
if nargin<1
return
else
mm= varargin{1};
d = find(size(mm) == 3);
if isempty(d),
error('wrong usage: vox = mm2vox(mm-coord, [fname])');
elseif d==1 && length(d)==1,
mm=mm'; %arrange coordinate triples in rows
end
if nargin<2
if exist('spm_select','file')
fname=spm_select(1,'image','select file defining space');
else
fname=spm_get(1,'*.img','select file defining space');
end
V=spm_vol(fname);
else
if isstruct(varargin{2}),
V=varargin{2};
else
V(1).fname=varargin{2};
end
end
end
v2m=spm_get_space(V(1).fname);
m2v=inv(v2m);
for i=1:size(mm,1)
vox(i,1:3)=mm(i,:)*m2v(1:3,1:3) + m2v(1:3,4)';
end
|