首页 > 解决方案 > 使用 SimpleITK 执行 3D 共定位和距离测量

问题描述

我正在尝试使用 python-simpleitk 处理一些相当大的(~150MB)3 通道 3D 图像。我需要确定红色通道中的对象是否与绿色通道中的对象重叠,并确定它们与蓝色通道中的对象的距离。

我在 simpleitk 文档中没有找到任何关于共定位的信息,所以我一直在尝试使用 numpy 来提取坐标并确定有多少体素重叠。我还没有找到任何特定的边到边距离测量方法。

然而,正如预期的那样,numpy 版本需要相当长的时间,我宁愿为此使用 simpleitk(我也研究过常规的 itk,但它会导致转换为 ndarrays 的问题)。

我想知道是否有人有幸使用这些工具执行这种类型的图像处理。或者可以提出改进建议。

到目前为止,这是我的代码。

class ChannelImage(object):

    def __init__(self, image:np.ndarray, metadata:dict):
        self.object_map = None
        self.image = sitk.GetImageFromArray(image)
        self.metadata = metadata
        self.channel_ID = metadata['Color']
        # threshold hardcoded for now.
        if self.channel_ID == "Blue":
            self.threshold = 20000
        else:
            self.threshold = 10000
        del self.metadata['ID']
        del self.metadata['Color']

    def get_coords(self):
        cc = sitk.ConnectedComponent(self.image>self.threshold)
        self.object_map = sitk.GetArrayFromImage(cc)
        stats = sitk.LabelIntensityStatisticsImageFilter()
        stats.Execute(cc, self.image)
        labels = stats.GetLabels()
        print(f"Getting coordinates for {self.channel_ID}")
        self.coords = {label:np.where(self.object_map==label) for label in labels}

标签: pythonnumpysimpleitk

解决方案


SimpleITK 目前没有直接获取标签坐标的方法。我建议为 SimpleITK 打开一个功能请求。

同时,您可以np.where通过基于该sitk.LabelIntensityStatisticsImageFilter.GetBoundingBox()方法裁剪 ndarray 来提高效率。


推荐阅读