🍠Python脑溶质扩散生理几何模型计算

关键词

Python | 命令行 | 脚本 | 体积 | 网格 | 加权 | 图像 | 几何 | 边界表面 | 分割 | 重建 | 内部体积 | 可视化 | 网格质量 | 平滑 | 生理 | 曲面 | 缺失 | 量化 | 扩散 | 浓度 | 磁共振

🏈指点迷津 | Brief

🎯要点

🎯生成体积网格:🖊从加权图像创建边界表面 | 🖊图像堆栈分割和表面重建 | 🖊生成内部体积网格 | 🖊转换网格为可视化数据格式 | 🖊重新网格化原始表面提高网格质量 | 🖊平滑表面减少非生理特征 | 🖊处理曲面相交和缺失面 | 🖊病理模型指定边界 | 🖊量化观察点 | 🖊数值计算扩散 | 🖊可视化给定时间示踪剂浓度。

🎯创建异质性:🖊灰质和白质的半球网格 | 🖊没有心室的半球网格 | 🖊两个半球创建脑网格 | 🖊分区映射到脑网格上,局部细化分区。

🎯脑溶质扩散张量:🖊提取平均扩散率和各向异性数据 | 🖊张量数据映射到加权图像。

🎯异质区各向异性扩散:🖊一维分子扩散 | 🖊三维大脑区域各向异性扩散。

🍇Python算法几何计算

该领域的应用很多:例如,在机器人技术中,这些应用用于解决可见性问题和运动规划。 类似的应用程序可用于设计地理信息系统 (GIS) 中的路线规划或搜索算法。

该类别的基本问题如下:

  • 凸包:给定空间中的一组点,找到包含它们的最小凸多面体。

  • 沃罗努图:给定空间中的一组点(种子),计算由靠近每个种子的所有点组成的区域的分区。

  • 三角剖分:用三角形划分平面,两个三角形要么不相交,要么共享一条边或一个顶点。 根据输入对象或三角形属性的约束,有不同的三角剖分。

  • 最短路径:给定空间中的一组障碍物和两个点,找到不与任何障碍物相交的点之间的最短路径。

💦凸包:

以下是某湖海岸线的多边形描述,有 7 个孔(用于岛屿)、518 个顶点和 518 个边。

 from numpy import array
 ​
 def read_poly(file_name):
 ​
     output = {'vertices': None, 'holes': None, 'segments': None}
 ​
     file = open(file_name, 'r')
     lines = file.readlines()
     file.close()
     lines = [x.strip('\n').split() for x in lines]
 ​
     vertices= []
     N_vertices, dimension, attr, bdry_markers = [int(x) for x in lines[0]]
 ​
     for k in range(N_vertices):
         label, x, y = [items for items in lines[k+1]]
         vertices.append([float(x), float(y)])
     output['vertices']=array(vertices)
 ​
     segments = []
     N_segments, bdry_markers = [int(x) for x in lines[N_vertices+1]]
     for k in range(N_segments):
         label, pointer_1, pointer_2 = [items for items in lines[N_vertices+k+2]]
         segments.append([int(pointer_1)-1, int(pointer_2)-1])
     output['segments'] = array(segments)
 ​
     N_holes = int(lines[N_segments+N_vertices+2][0])
     holes = []
     for k in range(N_holes):
         label, x, y = [items for items in lines[N_segments + N_vertices + 3 + k]]
         holes.append([float(x), float(y)])
     
     output['holes'] = array(holes)
     
     return output
 >>> import numpy as np
 >>> from scipy.spatial import ConvexHull
 >>> import matplotlib.pyplot as plt
 >>> lake_superior = read_poly("../ch/supe.poly")
 >>> vertices_ls = lake_superior['vertices']
 >>> %time hull = ConvexHull(vertices_ls)
 CPU times: user 413 µs, sys: 213 µs, total: 626 µs
 Wall time: 372 µs    
 ​
 >>> plt.figure(figsize=(14, 14))
 >>> plt.xlim(vertices_ls[:,0].min()-0.01, vertices_ls[:,0].max()+0.01)
 >>> plt.ylim(vertices_ls[:,1].min()-0.01, vertices_ls[:,1].max()+0.01)
 >>> plt.axis('off')
 >>> plt.axes().set_aspect('equal')
 >>> plt.plot(vertices_ls[:,0], vertices_ls[:,1], 'b.')
 >>> for simplex in hull.simplices:
 ...     plt.plot(vertices_ls[simplex, 0], vertices_ls[simplex, 1], 'r-')
 ...    
 >>> plt.show()

💦沃罗努图:

计算一组顶点的沃罗努图可以使用模块 scipy.spatial 中的例程来完成。

 >>> from scipy.spatial import Voronoi, voronoi_plot_2d
 >>> vor = Voronoi(vertices_ls)
 >>> plt.figure(figsize=(8, 8))
 >>> ax = plt.subplot(111, aspect='equal')
 >>> voronoi_plot_2d(vor, ax=ax)
 >>> plt.xlim( 0.45,  0.50)
 >>> plt.ylim(-0.40, -0.35)
 >>> plt.show()
  • 小点是原始种子,x 坐标在 0.450.50 之间,y 坐标在-0.40-0.35 之间。我们从原始列表 vertices_lsvor.points 访问这些值。

  • 该平面被划分为不同的区域,每个区域对应一个种子。 这些区域包含平面中最接近其种子的所有点。 每个区域接收一个索引,该索引不一定与其种子在 vor.points 列表中的索引相同。 要访问给定种子的相应区域,我们使用vor.point_region

 >>> vor.point_region
 array([  0,  22,  24,  21,  92,  89,  91,  98,  97,  26, 218, 219, 220,
        217, 336, 224, 334, 332, 335, 324, 226, 231, 230, 453, 500, 454,
        235, 234, 333, 236, 341, 340,  93, 343, 339, 342, 237, 327, 412,
        413, 344, 337, 338, 138,  67, 272, 408, 404, 403, 407, 406, 405,
        268, 269, 270, 257, 271, 258, 259,   2, 260, 261, 263,  15,  70,
         72, 278, 275, 277, 276, 179, 273, 274, 204, 289, 285, 288, 318,
        317, 216, 215, 312, 313, 309, 310, 243, 151, 150, 364, 365, 244,
        433, 362, 360, 363, 361, 242, 308, 307, 314, 311, 316, 315, 319,
        284, 287, 286, 452, 451, 450, 482, 483, 409, 493, 486, 485, 484,
        510, 516, 517, 410, 494, 518, 512, 515, 511, 513, 514, 508, 509,
        487, 214, 488, 489, 432, 429, 431, 430, 359, 490, 491, 492, 144,
        146, 147, 145, 149, 148, 143, 140, 142, 139, 141, 463, 428, 357,
        427, 462, 459, 461, 460, 426, 240, 239, 241, 352, 356, 355, 421,
        423, 424, 420, 422,  46,  47,  48, 112,  33,  32,  31, 110, 106,
        107, 105, 109, 108, 114, 111, 113, 358, 115,  44,   6, 133, 132,
        135, 134,  45, 127, 128, 129, 136, 130, 125, 126,  41,  36,  37,
         40, 131,   7, 123, 120,  39,  38,   4,   8, 118, 116, 122, 124,
         35, 101,  34, 100,  99, 121, 119, 103, 117, 102,   5,   1,  29,
        104,  28,  30, 304, 305, 306, 137, 207, 238, 348, 349, 300, 303,
         57, 302,  58,   9, 158, 295, 301, 347, 345, 346, 416, 351, 162,
        161,  53, 159, 160,  19,  20,  55,  56,  49, 298, 296, 299, 297,
        292, 291, 294, 206, 157, 154, 156,  52,  51, 155, 293,  50,  83,
         82,  84,  85, 250, 249, 246, 248, 153, 245, 247, 152, 209, 208,
        213, 211, 212, 371, 372, 375, 374, 442, 445, 441, 444, 438, 446,
        439, 440, 468, 467, 465, 470, 471, 505, 507, 464, 252, 253, 379,
        382, 378, 478, 476, 449, 398, 447, 475, 474, 477, 383, 381, 384,
        437, 466, 434, 435, 254, 165, 436, 387, 386, 385, 479, 480, 481,
        448, 395, 399, 400, 401, 256, 281, 280, 255, 391, 390, 396, 397,
        388, 389, 394, 393, 392, 163, 164, 166,  76, 192, 283, 279, 282,
        194, 203, 202, 195, 196, 185, 189, 187, 190, 191,  78, 181, 180,
        182,  75,  71, 264, 262,  73,  74,  59,  63,  62,  60,  61,  66,
         64,  65,  11,  12,  10,  13,  14,  69,  68, 233, 232,  88, 225,
        228, 227, 322, 229, 323, 320, 321, 223, 222, 221,  27,  25,  95,
         94,  96,  90,  86,  87,   3, 328, 325, 326, 499, 495, 498, 458,
        496, 497, 411, 329, 501, 457, 330, 456, 455, 331, 267, 266, 265,
        183, 188, 186, 184, 198, 197, 201, 193, 170, 169, 171, 175, 176,
        177, 402, 380, 167, 173, 172, 174, 178, 168,  80,  79,  16, 200,
        199,  81,  18,  17, 205, 290,  77, 503, 469, 473, 443, 373, 376,
        366, 370, 369, 210, 251, 367, 368, 377, 472, 504, 506, 502, 354,
        353,  54,  42,  43, 350, 417, 414, 415, 418, 419, 425])

Last updated