gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 21:24:00 28 4
gpt4 key购买 nike

我想计算两个二元对象之间的表面距离度量,也称为肝脏肿瘤的分割。我正在计算:

  • 平均对称表面距离
  • 均方根对称距离
  • 豪斯多夫距离(也称为最大对称距离)

我发现两个库可以帮助我计算这些指标,但我得到的结果相互矛盾,所以我很困惑它们是如何工作的。

这是我的 Simple ITK 和 MedPy 代码。

from medpy import metric
import pandas as pd
import SimpleITK as sitk
import numpy as np
reference_segmentation = sitk.ReadImage('tumorSegm', sitk.sitkUInt8)
segmentation = sitk.ReadImage('tumorSegm2',sitk.sitkUInt8)
class SurfaceDistanceMeasuresITK(Enum):
hausdorff_distance, max_surface_distance, avg_surface_distance, median_surface_distance, std_surface_distance = range(5)

class MedpyMetricDists(Enum):
hausdorff_distance, avg_surface_distance, avg_symmetric_surface_distance = range(3)


surface_distance_results = np.zeros((1,len(SurfaceDistanceMeasuresITK.__members__.items())))
surface_dists_Medpy = np.zeros((1,len(MedpyMetricDists.__members__.items())))
segmented_surface = sitk.LabelContour(segmentation)

# init signed mauerer distance as reference metrics
reference_distance_map = sitk.Abs(sitk.SignedMaurerDistanceMap(reference_segmentation, squaredDistance=False, useImageSpacing=True))

label_intensity_statistics_filter = sitk.LabelIntensityStatisticsImageFilter()
label_intensity_statistics_filter.Execute(segmented_surface, reference_distance_map)

hausdorff_distance_filter = sitk.HausdorffDistanceImageFilter()
hausdorff_distance_filter.Execute(reference_segmentation, segmentation)

surface_distance_results[0,SurfaceDistanceMeasuresITK.hausdorff_distance.value] = hausdorff_distance_filter.GetHausdorffDistance()
surface_distance_results[0,SurfaceDistanceMeasuresITK.max_surface_distance.value] = label_intensity_statistics_filter.GetMaximum(label)
surface_distance_results[0,SurfaceDistanceMeasuresITK.avg_surface_distance.value] = label_intensity_statistics_filter.GetMean(label)
surface_distance_results[0,SurfaceDistanceMeasuresITK.median_surface_distance.value] = label_intensity_statistics_filter.GetMedian(label)
surface_distance_results[0,SurfaceDistanceMeasuresITK.std_surface_distance.value] = label_intensity_statistics_filter.GetStandardDeviation(label)

surface_distance_results_df = pd.DataFrame(data=surface_distance_results, index = list(range(1)),
columns=[name for name, _ in SurfaceDistanceMeasuresITK.__members__.items()])

img_array = sitk.GetArrayFromImage(reference_segmentation)
seg_array = sitk.GetArrayFromImage(segmentation)
# reverse array in the order x, y, z
img_array_rev = np.flip(img_array,2)
seg_array_rev = np.flip(seg_array,2)
vxlspacing = segmentation.GetSpacing()

surface_dists_Medpy[0,MedpyMetricDists.hausdorff_distance.value] = metric.binary.hd(seg_array_rev,img_array_rev, voxelspacing=vxlspacing)
surface_dists_Medpy[0,MedpyMetricDists.avg_surface_distance.value] = metric.binary.asd(seg_array_rev,img_array_rev, voxelspacing=vxlspacing)
surface_dists_Medpy[0,MedpyMetricDists.avg_symmetric_surface_distance.value] = metric.binary.assd(seg_array_rev,img_array_rev, voxelspacing=vxlspacing)

surface_dists_Medpy_df = pd.DataFrame(data=surface_dists_Medpy, index = list(range(1)),
columns=[name for name, _ in MedpyMetricDists.__members__.items()])
  1. 乍一看,我不认为 SimpleITK 会计算对称距离。该库中的那些有任何实现吗?我怎样才能获得它们?

  2. MedPy 是一个可靠的库吗?我可以计算对称根均值吗与它成正方形吗?

  3. 计算表面距离的库的其他建议指标?
  4. 我应该计算毛雷尔距离图的绝对值吗?我不确定它如何影响结果。 reference_distance_map = sitk.Abs(sitk.SignedMaurerDistanceMap(reference_segmentation, squaredDistance=False, useImageSpacing=True))

最佳答案

@罗克珊

我在这里假设您对 this SimpleITK notebook 中计算的表面距离测量感到困惑?

答案的其余部分引用该代码。

平均值/标准差/中值/最大值不对称(豪斯多夫对称)。

使用 SimpleITK,您可以通过以下方式计算对称平均值和标准差计算分割的平均值和标准差,然后作为引用(代码是为了分割而计算的,所以只需切换角色即可获得它作为引用)。

现在您已获得两个样本的平均值和标准差。要获取样本的大小,只需调用:

label_intensity_statistics_filter.GetNumberOfPixels(label)

根据 n1,m1,s1, n2,m2,s2 的知识计算对称平均值和标准差:

m = (n1*m1 + n2*m2)/(n1+n2)
s = np.sqrt((n1*(s1**2+(m1-m)**2) + n2*(s2**2+(m2-m)**2))/(n1+n2))

请注意,标准差的样本估计是有偏差的版本(类似于 numpy.std 的默认行为)。

如果您还有其他问题,请发帖至ITK discourse forum .

关于python - 计算对称表面距离 [Python],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47282895/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com