使用 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 Oriented Bounding Box,按预期输出:
但是,使用 original_label_image.TransformPhysicalPointToContinousIndex() 后,原始图像空间中的定向边界框点出现错误(原始索引空间中的 shape_stats.OrientedBoundingBoxVertices()):
更新 2
使用 shape_stats.GetCentroid(),我可以正确获取每个标签质心的真实坐标并正确绘制它们:
看起来 shape_stats.GetOrientedBoundingBoxOrigin() 的输出似乎在真实世界坐标中。shape_stats.OrientedBoundingBoxVertices() 的一个元素对应于 shape_stats.GetOrientedBoundingBoxOrigin()。