python - 使用 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}
解决方案
SimpleITK 目前没有直接获取标签坐标的方法。我建议为 SimpleITK 打开一个功能请求。
同时,您可以np.where
通过基于该sitk.LabelIntensityStatisticsImageFilter.GetBoundingBox()
方法裁剪 ndarray 来提高效率。
推荐阅读
- google-bigquery - 大型 bigquery 加载作业的最可靠格式
- powershell - 通过一系列 Web 服务器远程部署代码
- swagger - 用于预定义示例的 Swagger-PHP 注释
- c - 在 while(1) 中保留开关
- sparql - 在 RDF 图中为文字定义数据类型有什么好处?
- javascript - 如何修复通知框插入符号?
- postgresql - SELECT ... WHERE t1.tag = 'bob' AND t2.tag = 'foo' AND t1.idx = t2.idx 在同一张桌子上
- html - 如何将搜索图标浮动到右侧
- python - 双 for 循环中的 Keras 模型
- python - 带有重复项的 Pandas 枢轴