matlab计算得到AAL脑图谱各个脑区ROI的质心坐标
·
问题描述:AAL脑图谱(自动解剖标记图谱)包含116个脑区。利用matlab程序计算各个脑区的质心坐标。
步骤:
第一步:
首先建立一个.m文件,命名为y_CenterOfMass.m :
function [Table] = y_CenterOfMass(AtlasFile)
%[Data Head]=y_Read('D:\PFC_ROI\aal\MFG_L.nii','all');
[Data Head]=y_Read(AtlasFile);
[nDim1 nDim2 nDim3]=size(Data);
[I J K] = ndgrid(1:nDim1,1:nDim2,1:nDim3);
Element = unique(Data);
Element(1) = []; % This is the background 0
Table = [];
for iElement=1:length(Element)
ICenter = mean(I(Data==Element(iElement)));
JCenter = mean(J(Data==Element(iElement)));
KCenter = mean(K(Data==Element(iElement)));
Center = Head.mat*[ICenter JCenter KCenter 1]';
XCenter = Center(1);
YCenter = Center(2);
ZCenter = Center(3);
Table = [Table;[iElement,Element(iElement),ICenter,JCenter,KCenter,XCenter,YCenter,ZCenter]];
end
% % 定义文件路径
% AtlasFile = 'D:/aal/MFG_L.nii';
%
% % 调用 y_CenterOfMass 函数
% Table = y_CenterOfMass(AtlasFile);
注意:在这个文件中不能直接调用函数,因为在MATLAB中,一个 .m 文件如果第一行是以 function 关键字开头的函数定义(例如这里的 function [Table] = y_CenterOfMass(AtlasFile)),那么整个文件就会被MATLAB视为一个函数文件。
如果想要直接运行函数,可手动把[Data Head]=y_Read(AtlasFile);这一句的AtlasFile参数改成nii文件路径。
第二步:
在当前的工作目录下新建另一个.m文件,比如这里命名为test_center_of_mass.m :
% test_center_of_mass.m (独立的脚本文件)
% 定义文件路径
AtlasFile = 'D:/PFC_ROI/aal/aal.nii';
% 调用 y_CenterOfMass 函数
Table = y_CenterOfMass(AtlasFile);
disp(Table)
运行此程序后,即可输出每个脑区的质心坐标:
>> test_center_of_mass
1.0000 1.0000 51.3504 120.3167 122.9442 -39.6496 -5.6833 50.9442
2.0000 2.0000 131.3746 117.7869 124.0920 40.3746 -8.2131 52.0920
3.0000 3.0000 71.5543 160.8081 114.2017 -19.4457 34.8081 42.2017
4.0000 4.0000 111.8997 157.1201 115.8154 20.8997 31.1201 43.8154
5.0000 5.0000 73.4396 173.3247 58.6932 -17.5604 47.3247 -13.3068
6.0000 6.0000 108.4947 174.0980 57.9799 17.4947 48.0980 -14.0201
7.0000 7.0000 56.5682 158.7318 107.4556 -34.4318 32.7318 35.4556
8.0000 8.0000 127.5948 159.0619 106.0351 36.5948 33.0619 34.0351
9.0000 9.0000 59.3543 176.4297 62.3810 -31.6457 50.4297 -9.6190
10.0000 10.0000 123.1817 178.5879 61.2688 32.1817 52.5879 -10.7312
11.0000 11.0000 41.5662 138.7333 91.0225 -49.4338 12.7333 19.0225
12.0000 12.0000 140.2040 140.9765 93.4118 49.2040 14.9765 21.4118
13.0000 13.0000 44.4168 155.9140 85.9904 -46.5832 29.9140 13.9904
14.0000 14.0000 140.3297 156.1618 86.1734 49.3297 30.1618 14.1734
15.0000 15.0000 54.0152 156.7074 59.8902 -36.9848 30.7074 -12.1098
16.0000 16.0000 131.2244 158.2303 60.0890 40.2244 32.2303 -11.9110
17.0000 17.0000 42.8415 117.5245 85.9507 -48.1585 -8.4755 13.9507
18.0000 18.0000 142.6468 119.7478 86.6347 51.6468 -6.2522 14.6347
19.0000 19.0000 84.6760 130.8485 133.3755 -6.3240 4.8485 61.3755
20.0000 20.0000 98.6158 126.1714 133.8538 7.6158 0.1714 61.8538
21.0000 21.0000 81.9372 141.0531 60.5447 -9.0628 15.0531 -11.4553
22.0000 22.0000 100.4269 141.9121 60.7437 9.4269 15.9121 -11.2563
23.0000 23.0000 85.2006 175.1687 102.8937 -5.7994 49.1687 30.8937
24.0000 24.0000 99.0994 176.8406 102.2193 8.0994 50.8406 30.2193
25.0000 25.0000 84.8260 180.0571 64.6032 -6.1740 54.0571 -7.3968
26.0000 26.0000 98.1611 177.6710 64.8659 7.1611 51.6710 -7.1341
27.0000 27.0000 84.9181 163.0724 53.8638 -6.0819 37.0724 -18.1362
28.0000 28.0000 98.3533 161.6447 53.9560 7.3533 35.6447 -18.0440
29.0000 29.0000 54.8690 132.6518 75.4409 -36.1310 6.6518 3.4409
30.0000 30.0000 129.0191 132.2451 74.0775 38.0191 6.2451 2.0775
31.0000 31.0000 85.9634 161.3999 85.9529 -5.0366 35.3999 13.9529
32.0000 32.0000 98.4557 163.0056 87.8398 7.4557 37.0056 15.8398
33.0000 33.0000 84.5236 111.0802 113.5694 -6.4764 -14.9198 41.5694
34.0000 34.0000 98.0204 117.1736 111.7910 7.0204 -8.8264 39.7910
35.0000 35.0000 85.1524 83.0821 96.6697 -5.8476 -42.9179 24.6697
36.0000 36.0000 97.4375 84.1850 93.8666 6.4375 -41.8150 21.8666
37.0000 37.0000 64.9732 105.2588 61.8665 -26.0268 -20.7412 -10.1335
38.0000 38.0000 119.2307 106.2168 61.6688 28.2307 -19.7832 -10.3312
39.0000 39.0000 68.8289 110.0497 51.2957 -22.1711 -15.9503 -20.7043
40.0000 40.0000 115.3818 110.8532 51.5298 24.3818 -15.1468 -20.4702
41.0000 41.0000 66.7311 125.3329 54.8586 -24.2689 -0.6671 -17.1414
42.0000 42.0000 117.3191 126.6387 54.4972 26.3191 0.6387 -17.5028
43.0000 43.0000 82.8583 47.3330 78.4392 -8.1417 -78.6670 6.4392
44.0000 44.0000 105.9942 52.8517 81.4048 14.9942 -73.1483 9.4048
45.0000 45.0000 84.0660 45.8664 99.2235 -6.9340 -80.1336 27.2235
46.0000 46.0000 103.5110 46.6418 100.2284 12.5110 -79.3582 28.2284
47.0000 47.0000 75.3831 58.4450 67.3671 -15.6169 -67.5550 -4.6329
48.0000 48.0000 106.2899 59.0741 68.1253 15.2899 -66.9259 -3.8747
49.0000 49.0000 73.4593 41.7377 100.1653 -17.5407 -84.2623 28.1653
50.0000 50.0000 114.2915 45.1461 102.5870 23.2915 -80.8539 30.5870
51.0000 51.0000 57.6115 45.2684 88.1148 -33.3885 -80.7316 16.1148
52.0000 52.0000 127.3877 46.2954 91.4158 36.3877 -79.7046 19.4158
53.0000 53.0000 53.6413 47.7070 64.1557 -37.3587 -78.2930 -7.8443
54.0000 54.0000 128.1587 44.0069 64.3868 37.1587 -81.9931 -7.6132
55.0000 55.0000 58.8407 85.7022 51.7718 -32.1593 -40.2978 -20.2282
56.0000 56.0000 123.9681 86.8983 51.8216 32.9681 -39.1017 -20.1784
57.0000 57.0000 47.5376 103.3687 120.9172 -43.4624 -22.6313 48.9172
58.0000 58.0000 131.4284 100.5069 124.5450 40.4284 -25.4931 52.5450
59.0000 59.0000 66.5464 66.4428 130.9601 -24.4536 -59.5572 58.9601
60.0000 60.0000 116.1058 66.8202 134.0618 25.1058 -59.1798 62.0618
61.0000 61.0000 47.1963 80.1803 118.7405 -43.8037 -45.8197 46.7405
62.0000 62.0000 136.4620 79.7103 121.5351 45.4620 -46.2897 49.5351
63.0000 63.0000 34.2119 92.3622 102.4495 -56.7881 -33.6378 30.4495
64.0000 64.0000 147.6107 94.4951 106.4800 56.6107 -31.5049 34.4800
65.0000 65.0000 45.8587 65.1842 107.5872 -45.1413 -60.8158 35.5872
66.0000 66.0000 135.5077 66.0153 110.6277 44.5077 -59.9847 38.6277
67.0000 67.0000 82.7592 69.9291 120.0090 -8.2408 -56.0709 48.0090
68.0000 68.0000 99.9796 69.9505 115.7694 8.9796 -56.0495 43.7694
69.0000 69.0000 82.3699 100.6354 142.0703 -8.6301 -25.3646 70.0703
70.0000 70.0000 97.4771 94.4130 140.0941 6.4771 -31.5870 68.0941
71.0000 71.0000 78.5381 136.9960 81.2391 -12.4619 10.9960 9.2391
72.0000 72.0000 104.8362 138.0743 81.4152 13.8362 12.0743 9.4152
73.0000 73.0000 66.0863 129.8553 74.4013 -24.9137 3.8553 2.4013
74.0000 74.0000 117.7787 130.9129 74.4647 26.7787 4.9129 2.4647
75.0000 75.0000 72.2503 125.9685 72.2105 -18.7497 -0.0315 0.2105
76.0000 76.0000 111.2006 126.1755 72.2281 20.2006 0.1755 0.2281
77.0000 77.0000 79.1516 108.4355 79.9761 -11.8484 -17.5645 7.9761
78.0000 78.0000 102.9977 108.4476 80.0868 11.9977 -17.5524 8.0868
79.0000 79.0000 48.0083 107.1247 81.9784 -42.9917 -18.8753 9.9784
80.0000 80.0000 135.8569 108.8533 82.4060 44.8569 -17.1467 10.4060
81.0000 81.0000 36.8435 105.3224 79.1348 -54.1565 -20.6776 7.1348
82.0000 82.0000 148.1460 104.2194 78.8014 57.1460 -21.7806 6.8014
83.0000 83.0000 50.1214 141.1441 51.8173 -40.8786 15.1441 -20.1827
84.0000 84.0000 138.2468 140.7452 55.1368 47.2468 14.7452 -16.8632
85.0000 85.0000 34.4761 92.2002 69.7990 -56.5239 -33.7998 -2.2010
86.0000 86.0000 147.4735 88.7720 70.5319 56.4735 -37.2280 -1.4681
87.0000 87.0000 53.6801 140.5869 37.9191 -37.3199 14.5869 -34.0809
88.0000 88.0000 134.2204 140.5516 39.7668 43.2204 14.5516 -32.2332
89.0000 89.0000 40.2293 97.9484 48.8316 -50.7707 -28.0516 -23.1684
90.0000 90.0000 143.6922 94.9308 49.6811 52.6922 -31.0692 -22.3189
91.0000 91.0000 54.9330 59.2803 43.0656 -36.0670 -66.7197 -28.9344
92.0000 92.0000 128.4559 58.8632 42.4525 37.4559 -67.1368 -29.5475
93.0000 93.0000 62.3642 52.7397 33.7963 -28.6358 -73.2603 -38.2037
94.0000 94.0000 123.0575 56.9841 32.0513 32.0575 -69.0159 -39.9487
95.0000 95.0000 82.1996 88.7771 53.4188 -8.8004 -37.2229 -18.5812
96.0000 96.0000 103.3187 91.5344 52.6088 12.3187 -34.4656 -19.3912
97.0000 97.0000 75.9960 82.5139 55.0671 -15.0040 -43.4861 -16.9329
98.0000 98.0000 108.1987 83.1391 53.8492 17.1987 -42.8609 -18.1508
99.0000 99.0000 67.7621 66.8993 49.8694 -23.2379 -59.1007 -22.1306
100.0000 100.0000 115.6914 67.6837 48.3549 24.6914 -58.3163 -23.6451
101.0000 101.0000 58.6422 66.1798 26.5505 -32.3578 -59.8202 -45.4495
102.0000 102.0000 124.1392 62.8220 23.5428 33.1392 -63.1780 -48.4572
103.0000 103.0000 65.2486 71.4809 24.3154 -25.7514 -54.5191 -47.6846
104.0000 104.0000 116.0640 69.6602 22.5320 25.0640 -56.3398 -49.4680
105.0000 105.0000 80.0526 77.0495 26.0971 -10.9474 -48.9505 -45.9029
106.0000 106.0000 100.4602 76.5005 25.6732 9.4602 -49.4995 -46.3268
107.0000 107.0000 68.3858 92.2002 30.2352 -22.6142 -33.7998 -41.7648
108.0000 108.0000 116.9945 92.1617 30.6531 25.9945 -33.8383 -41.3469
109.0000 109.0000 91.7574 87.2079 51.9505 0.7574 -38.7921 -20.0495
110.0000 110.0000 92.3804 86.0692 60.6021 1.3804 -39.9308 -11.3979
111.0000 111.0000 92.2207 73.6384 65.8862 1.2207 -52.3616 -6.1138
112.0000 112.0000 92.1414 58.9415 56.8769 1.1414 -67.0585 -15.1231
113.0000 113.0000 92.1458 54.0697 46.8593 1.1458 -71.9303 -25.1407
114.0000 114.0000 92.1521 61.5706 37.9201 1.1521 -64.4294 -34.0799
115.0000 115.0000 91.8647 71.1251 37.1039 0.8647 -54.8749 -34.8961
116.0000 116.0000 91.3558 80.2002 40.3169 0.3558 -45.7998 -31.6831
输出解读:
第一列:ROI的索引,即标签序号。
第二列:区域的标签值,即该ROI的像素值。
第三列:质心在图像坐标系中的 I 坐标。
第四列:质心在图像坐标系中的 J 坐标。
第五列:质心在图像坐标系中的 K 坐标。
第六列:质心在物理坐标系中的 X 坐标。
第七列:质心在物理坐标系中的 Y 坐标。
第八列:质心在物理坐标系中的 Z 坐标。
注:此程序也可用来计算单一脑区的质心坐标,输入一个ROI,会输出相应的单个质心坐标。
参考资料:
分享一些有用的程序
DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐

所有评论(0)