How to determine the voxel size in an image

40 sec read

Tools: SPM, cor2mni

Assume the image is “a.img”, do

v = spm_vol('a.img');
v.mat

If v.mat is a diagonal matrix, you can simply read the number and they are the voxel size in mm.

If not, a trick is to calculate the distance between adjacent voxels. For example, if v.mat =

   -3.4337   -0.0518   -0.1776  110.2825
   -0.0919    3.3036    1.1004  -97.8366
   -0.1324   -0.9487    3.8416   19.7459
         0         0         0    1.0000

Use cor2mni.m to calculate the voxel coordinate in MNI space.

point1 = cor2mni([1 1 1], v.mat);
point2 = cor2mni([1 1 2], v.mat);

Then calculate the distance between point1 and point2 you will get the voxel size in z direction. Repeat for x and y direction.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% 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;



文献鸟 618 活动


写作助手,把中式英语变成专业英文


Want to receive new post notification? 有新文章通知我

第六十四期fNIRS Journal Club通知2025/7/12, 10am 黄润玉

该文章的声音简介(中文版): 该文章的声音简介(英文版): 随着全球老龄化加剧,越来越多老年人面临数字化适应、子女异地独居适应等问题。在青年志愿者人数明显不足以覆盖老龄人口的现实情况下,让老年同龄人进
Wanling Zhu
9 sec read

第六十三期fNIRS Journal Club视频 张百强

Youtube: https://youtu.be/vBsdcx08ZV4 优酷:https://v.youku.com/video?vid=XNjQ4NTcxNjM4MA%3D%3D fNIRS信号
Wanling Zhu
13 sec read

第六十三期fNIRS Journal Club通知2025/6/14, 10am 张百强

该文章的声音简介(中文版): 该文章的声音简介(英文版): fNIRS信号容易受到头动伪影、接触不良以及生理噪声等影响,导致测量信号信噪比低和数据浪费。来自北京师范大学牛海晶课题组的张百强同学将分享一
Wanling Zhu
9 sec read

One Reply to “How to determine the voxel size in an image”

  1. Dear,

    Thank you so much for your valubale comments, In fact I would like to perform a Multi Class SVM using LibSVM, could you please do me a big favor and help me ? for example how optimize the parameters? and …

    I am looking forward to hearing from you
    Kind Regards
    Mohammad

Leave a Reply

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