SimpleITK OrientedBoundingBoxVertices - 在什么坐标系中定义顶点?

标签 simpleitk

使用 LabelShapeStatisticFilter,我可以从原始图像中正确提取定向感兴趣区域。我想在原始图像上绘制这些定向边界框。

当我尝试查看 GetOrientedBoundingBoxVertices() 方法的输出时,我不清楚这些顶点是在什么坐标系中定义的。它们似乎不在原始图像坐标系中。

我确信我正在按预期使用 LabelShapeStatisticFilter 类(见下文),遵循这个出色的笔记本:http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/35_Segmentation_Shape_Analysis.html

bacteria_labels = shape_stats.GetLabels()
bacteria_volumes = [shape_stats.GetPhysicalSize(label) for label in bacteria_labels] 
num_images = 5 # number of bacteria images we want to display

bacteria_labels_volume_sorted = [label for _,label in sorted(zip(bacteria_volumes, bacteria_labels))]

resampler = sitk.ResampleImageFilter()
aligned_image_spacing = [10,10,10] #in nanometers

for label in bacteria_labels_volume_sorted[0:num_images]:
    aligned_image_size = [ int(ceil(shape_stats.GetOrientedBoundingBoxSize(label)[i]/aligned_image_spacing[i])) for i in range(3) ]
    direction_mat = shape_stats.GetOrientedBoundingBoxDirection(label)
    aligned_image_direction = [direction_mat[0], direction_mat[3], direction_mat[6], 
                               direction_mat[1], direction_mat[4], direction_mat[7],
                               direction_mat[2], direction_mat[5], direction_mat[8] ] 
    resampler.SetOutputDirection(aligned_image_direction)
    resampler.SetOutputOrigin(shape_stats.GetOrientedBoundingBoxOrigin(label))
    resampler.SetOutputSpacing(aligned_image_spacing)
    resampler.SetSize(aligned_image_size)

    obb_img = resampler.Execute(img)
    # Change the image axes order so that we have a nice display.
    obb_img = sitk.PermuteAxes(obb_img,[2,1,0])
    gui.MultiImageDisplay(image_list = [obb_img],                   
                          title_list = ["OBB_{0}".format(label)])

我希望能够在原始图像上绘制这些边界框,但我不确定如何绘制。

更新

也许这更能说明我的意思。重新采样的定向边界框,按预期输出:

resampled

但是,使用original_label_image.TransformPhysicalPointToContinousIndex()后,原始图像空间中的定向边界框点显示不正确(原始索引空间中的shape_stats.OrientedBoundingBoxVertices()):

original label image

更新2

使用 shape_stats.GetCentroid(),我可以正确获取每个标签质心的真实坐标并正确绘制它们:

centroids

看来 shape_stats.GetOrientedBoundingBoxOrigin() 的输出似乎在真实世界坐标中。 shape_stats.OrientedBoundingBoxVertices() 的一个元素对应于 shape_stats.GetOrientedBoundingBoxOrigin()。

enter image description here

最佳答案

顶点是在物理空间而不是索引空间中定义的。您可能需要使用 Image 类的 TransformPhysicslPointToIndex。

关于SimpleITK OrientedBoundingBoxVertices - 在什么坐标系中定义顶点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57205141/

相关文章:

python - 计算对称表面距离 [Python]

python - 为什么 ConnectedThresholdImageFilter 类没有标记阈值内的像素?

python - 如何处理使用 simpleITK 加载的图像中的负像素值

matplotlib - 阈值大津: AttributeError: 'AxesSubplot' object has no attribute 'ravel'

python - 配准不同视场的非各向同性 CT 扫描

python - SimpleITK 的 sudo easy_install 没那么容易

Python - 从 3D 数组写入三维图像

python - 在使用 simpleITK (python) 注册期间捕获警告