Convert coordinates in MNI space to matrix space

43 sec read

Quite often you need to convert the coordinates of some voxels in MNI space to regular matrix coordinates. Below is a script to do so:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% mni2cor
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function coordinate = mni2cor(mni, T)
% function coordinate = mni2cor(mni, T)
% convert mni coordinate to matrix coordinate
%
% mni: a Nx3 matrix of mni coordinate
% T: (optional) transform matrix
% coordinate is the returned coordinate in matrix
%
% caution: if T is not specified, we use:
% T = ...
%     [-4     0     0    84;...
%      0     4     0  -116;...
%      0     0     4   -56;...
%      0     0     0     1];
%
% xu cui
% 2004-8-18
%

if isempty(mni)
    coordinate = [];
    return;
end

if nargin == 1
	T = ...
        [-4     0     0    84;...
         0     4     0  -116;...
         0     0     4   -56;...
         0     0     0     1];
end

coordinate = [mni(:,1) mni(:,2) mni(:,3) ones(size(mni,1),1)]*(inv(T))';
coordinate(:,4) = [];
coordinate = round(coordinate);
return;

If you need to convert from matrix coordinates to MNI space, then here is the code:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% cor2mni
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function mni = cor2mni(cor, T)
% function mni = cor2mni(cor, T)
% convert matrix coordinate to mni coordinate
%
% cor: an Nx3 matrix
% T: (optional) rotation matrix
% mni is the returned coordinate in mni space
%
% caution: if T is not given, the default T is
% T = ...
%     [-4     0     0    84;...
%      0     4     0  -116;...
%      0     0     4   -56;...
%      0     0     0     1];
%
% xu cui
% 2004-8-18
% last revised: 2005-04-30

if nargin == 1
    T = ...
        [-4     0     0    84;...
         0     4     0  -116;...
         0     0     4   -56;...
         0     0     0     1];
end

cor = round(cor);
mni = T*[cor(:,1) cor(:,2) cor(:,3) ones(size(cor,1),1)]';
mni = mni';
mni(:,4) = [];
return;


Receive email notification via email
Don't want to miss new papers in your field? Check out Stork we developed:

fNIRS Journal Club 视频

546个被试的大型实验是怎么做的?近红外超扫描技术如何揭开群体冲突的神经机制?北京时间2020年5月29日周五上午11点,北京师范大学的马燚娜教授(Yina Ma)为大家讲解了她们组刚刚在Nature Neuroscience发表的文章。下面是报告视频。第一个是在Youtube,第二个是在youku。 Youtube:https://www.youtube.com/watch?v=4qZ7zP-BGz4Youku:https://v.youku.com/v_show/id_XNDY5MTc0MjAxMg==.html 她讲的文献如下: Within-group synchronization in the prefrontal cortex associates with intergroup conflict. Nature neuroscience https://www.storkapp.me/pubpaper/32341541 中文摘要(人工智能翻译,仅供参考):陷入群体的个人有时会失去自己的个性,冒着通常会避免的风险,以无端的敌对态度与外界接触。在这项研究中,我们确定了右侧背外侧前额叶皮层(rDLPFC)和右侧颞顶交界处(rTPJ)的组内神经同步是组间敌对性的潜在机制。我们将546个人组织为91个三对三人小组间比赛,诱导了组内亲和,并使用功能性近红外光谱仪测量了神经活动和组内同步。在组内亲和之后,个人给组内成员的钱比给组外成员的钱多,并且捐出更多的钱来击败竞争对手。组内亲和减少了rDLPFC的活动,并增加了rDLPFC和rTPJ之间的功能连接。尤其是在组外攻击期间,组内亲和还增加了rDLPFC和rTPJ中的组内同步,并且组内rDLPFC同步与组间敌对性正相关。组内同步减少前额活动可能可以解释组内联结如何导致对外界的冲动和集体敌视。
Xu Cui
13 sec read

Remote fNIRS

Everytime I met Dr Leanne Hirshfield, I am impressed by her energy and passion with the fNIRS technology. It was a pleasure listening to...
Xu Cui
4 min read

fNIRS Journal Club 通知 2020/5/29, 11am

546个被试的大型实验是怎么做的?近红外超扫描技术如何揭开群体冲突的神经机制?北京时间2020年5月29日周五上午11点,北京师范大学的马燚娜教授(Yina Ma)将为大家讲解她们组刚刚在Nature Neuroscience发表的文章。 欢迎大家参加并参与讨论。 时间: 北京时间2020年5月29日周五上午11点 地点: https://zoom.com/j/84320310196房间号: 843 2031 0196 密码: 600516 她要讲的文献如下: Within-group synchronization in the prefrontal cortex associates with intergroup conflict....
Xu Cui
7 sec read

23 Replies to “Convert coordinates in MNI space to matrix space”

  1. thanks – exactly what I needed!

    My transformation matrix was the following:
    [ans.hdr.hist.srow_x; ans.hdr.hist.srow_y; ans.hdr.hist.srow_z; 0 0 0 1]

  2. Dear Xu,

    thanks for the code. Can you give me a hint how to obtain the transformation matrix? I know that I have to define several fiducials on my images (like anterior and posterior commissure), but I don’t know of any convenient way (i.e. software) to do this and get mni coordinates from voxel indices. Are you aware of a simple way to do that?

    Thanks a lot,
    Michael

    P.S.: Great motto for your blog 🙂

  3. @Xu Cui
    As far as I know, this only results in valid mni coordinates, as long as the image is in alignment with normal space, i.e., with MNI152 – in all other cases it will give me an arbitrary transformation matrix.

  4. Dear Xu,
    thanks, very helpful. This helps me a lot! One related question: I have a set of images that are in a coordinate space and a 4×4 transformation matrix that I can use to covert the cooridnates into mni [3 0 0 81; 0 3 0 -115; 0 0 3 -70; 0 0 0 1]; I could now apply this transformation while looping over all voxels, but that seems cumbersome. Is there a function that could transform the whole 3D (or 4d – 3D +timeseries) from its space into MNI?

    Best, Ralf

  5. Dear Dr. Cui,
    I obtained a transformation matrix from an image preprocessed in SPM (normalized to MNI template already) but when I use this function, the location showing up in the mask is L/R flipped: e.g., in MNI coordinate it was on the left but after putting into the matrix space, it showed up on the right of the image. Is there a parameter i should obtain from spm_vol to know if my data is L/R flipped?
    Thanks!

  6. Dear Dr. Cui,
    I have a problem. I first time have to MNI coordinates to matrix space convert. What am I going to change in the code?
    When entered values mni e.g. -41 -4 10 I have error and the program does not work.
    Is it working for lots of coordinates?

    function coordinate=mni2cor(-41,-4,10), T)
    if isempty(mni)
    coordinate= [];
    return;
    end
    if nargin ==1
    T = …
    [-4 0 0 -84; …
    0 4 0 -116;…
    0 0 4 -56;…
    0 0 0 1];
    end
    coordinate=[mni(:,1) mni(:,2) mni(:,3) ones(size(mni,1),1)]*(inv(T))’;
    coordinate(:,4)=[];
    coordinate=round(coordinate);
    return;

    Best,Ila

  7. Dear Dr. Cui,
    Thank you for your answer. I understand what do you write, but can you give me an example on one of coordination? Unfortunately, it is not clear for me and my friends.
    I need easy example how define mni?

    These are my hard beginnings..
    Best, Ila

  8. Dear Dr Cui,
    My aim is to write a matlabs function to convert an MNI coordinate into voxel space of the AAL template which can then give me the anatomical labelling. MRIcron already does this, but I wanted to automate this in script form rather than GUI form.
    I was hoping to use your mni2cor function but the result doesn’t match with the MNI-voxel conversion as found in MRIcron or SPM. For example, the x y z MNI coordinate of 39,4,58 in the aal template is equivalent to the voxel coordinates of 130 130 130. However, if I use your mni2cor function, leaving the T undefined, gives me the coordinate of 11 30 29 rather than the expected 130 130 130.
    I am sure I missing something here, and I suspect it has something to do with how the image (aal) is sliced. Would you be able to help?
    Thank you in advance,
    Francesca

  9. Oh I just figured it out: the transformation is based on the ratio between MNI and cor, which I can easily calculate. So basically the problem, now solved, was that I needed to define T.

    Thank you anyway.

  10. Hi Xu,

    I have a matrix (9142×9142 single) that represents correlation matrix between two brain areas, and I want to get brain images showing the correlation. Is this program usable for that? Not sure about the input matrix.

    Thanks,
    Fran

  11. Dear Dr Cui
    I want to use your code to convert FEM based head model to MNI space. Could you kindly give me any reference of yours so that i can refer it on my publication.

    Regards
    Dr.Rajan Kashyap

  12. Dear Dr. Cui

    As the transformation is based on the ratio between MNI and cor, please can you explain to me the “T”? And how to calculate the ratio between MNI and cor?

    Regards
    Abdul

  13. Dear Dr. Cui

    I used spm_vol function to get the transform matrix (T). When I tried to convert a voxel coordinate [30,-2,12] from MNI to native space, I got this coordinate [14,24,11], which is different from the coordinates that I got from MRIcro [41,18,15].
    I think I am missing something here. Please help me to understand.
    Regards
    Abdul

    1. Abdul,

      Since I do not use MRIcro, I am not sure how it converts between MNI and matrix coordiantes. I think SPM conversion is accurate.

      Xu

Leave a Reply to Abdul Cancel reply

Your email address will not be published. Required fields are marked *