surface dice
生活随笔
收集整理的這篇文章主要介紹了
surface dice
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
nnUNet中的設(shè)計(jì)surface dice的計(jì)算方法:?
import numpy as np from medpy.metric.binary import __surface_distancesdef normalized_surface_dice(a: np.ndarray, b: np.ndarray, threshold: float, spacing: tuple = None, connectivity=1):"""This implementation differs from the official surface dice implementation! These two are not comparable!!!!!The normalized surface dice is symmetric, so it should not matter whether a or b is the reference imageThis implementation natively supports 2D and 3D images. Whether other dimensions are supported depends on the__surface_distances implementation in medpy:param a: image 1, must have the same shape as b:param b: image 2, must have the same shape as a:param threshold: distances below this threshold will be counted as true positives. Threshold is in mm, not voxels!(if spacing = (1, 1(, 1)) then one voxel=1mm so the threshold is effectively in voxels)must be a tuple of len dimension(a):param spacing: how many mm is one voxel in reality? Can be left at None, we then assume an isotropic spacing of 1mm:param connectivity: see scipy.ndimage.generate_binary_structure for more information. I suggest you leave thatone alone:return:"""assert all([i == j for i, j in zip(a.shape, b.shape)]), "a and b must have the same shape. a.shape= %s, " \"b.shape= %s" % (str(a.shape), str(b.shape))if spacing is None:spacing = tuple([1 for _ in range(len(a.shape))])a_to_b = __surface_distances(a, b, spacing, connectivity)b_to_a = __surface_distances(b, a, spacing, connectivity)numel_a = len(a_to_b)numel_b = len(b_to_a)tp_a = np.sum(a_to_b <= threshold) / numel_atp_b = np.sum(b_to_a <= threshold) / numel_bfp = np.sum(a_to_b > threshold) / numel_afn = np.sum(b_to_a > threshold) / numel_bdc = (tp_a + tp_b) / (tp_a + tp_b + fp + fn + 1e-8) # 1e-8 just so that we don't get div by 0return dc使用:
seg = sitk.ReadImage(os.path.join(seg_path, file), sitk.sitkInt8)label = sitk.ReadImage(os.path.join(label_path), sitk.sitkInt8) label_array = sitk.GetArrayFromImage(label)seg_array = sitk.GetArrayFromImage(seg)dice = normalized_surface_dice(label_array,seg_array,1)總結(jié)
以上是生活随笔為你收集整理的surface dice的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 车载android语音系统设计,基于An
- 下一篇: 平面设计主要学什么软件,平面设计需要掌握