问题:
使用3d网络模型分割,分割出来的结果与真值图计算hd95,网上查找了许多办法,但大多都是2d的计算方式,不适用我的结果,又或者是因为我没有想到适用我的方法。最终找到一个medpy函数库计算hd95的值。
medpy函数库详情参考链接:medpy.metric.binary.hd — MedPy 0.4.0 documentation
使用方法:
from medpy.metric import binary
#计算hd
hd=binary.hd(Vseg, Vref, voxelspacing=None)
#hd95
hd95=binary.hd95(Vseg, Vref, voxelspacing=None)
遇到错误:
大概就是错误提示数组值为0,具体的我没有保存,不想再实验一次了。又或者改用下面的方法出现相似的错误。
在使用如下代码计算hd距离时:
def hausdorff_distance(lT,lP):
labelPred=sitk.GetImageFromArray(lP, isVector=False)
labelTrue=sitk.GetImageFromArray(lT, isVector=False)
hausdorffcomputer=sitk.HausdorffDistanceImageFilter()
hausdorffcomputer.Execute(labelTrue>0.5,labelPred>0.5)
return hausdorffcomputer.GetAverageHausdorffDistance()#hausdorffcomputer.GetHausdorffDistance()
遇到了如下错误:
python使用SimpleITK出现问题
RuntimeError:Exception thrown in SimpleITK hausdorffDistanceImageFilter_Execute: ../ITK-prefix/include/ITK-5.1/itkDirectedHausdorffDistanceImageFilter.hxx:168:
itk::ERROR:pixelcount is equal to 0
分析原因:
发现预测结果可能会出现空白的情况,即可能会遇到某个数组全为0,导致不仅进行接下来的计算。
解决方法:
根据预测图像以及真值图的值进行判断 ,作为判断条件分情况给hd赋值
(大致就是假阳性时hd赋值取最大,若是遇到真值预测均为空白hd则赋值0)
【这只是wo私以为的方法,还请各位大佬批评指正,希望可以温柔一点哦 : ) !!!】
代码实现:
暂略!