分割/配准常见评价指标dice/hd

# -*- coding: utf-8 -*-
import cv2
import numpy as np
import os
from medpy import metric #安装medpy包
gty=cv2.imread("C:/Users/lenovo/Desktop/data_image/1/"+file,2)# 读取label文件
gtx=cv2.imread("C:/Users/lenovo/Desktop/data_image/1/"+file.split("g")[0]+"gtx.tif",2)# 读取label文件
Hausdorff1=metric.hd(gty,gtx,voxelspacing= 0.3515625) #voxelspacing表示图像的物理距离,一般医学图像里面会有这个
dice1=metric.dc(gty,gtx)
#其他的评价指标metric里面有详细介绍 直接调用即可
print(Hausdorff1)
print(dice1)
### 分割常见评价指标 在IT领域中,图像分割是计算机视觉与医学图像处理中的重要任务。为了评估这些任务的效果,通常使用一系列定量指标来衡量模型的性能。以下是常见评价指标及其定义: #### 1. Dice系数 Dice系数是一种用于衡量两个样本集合相似性的统计工具,广泛应用于图像分割任务中。其计算公式如下: ```python def dice_coefficient(segmentation, ground_truth): intersection = np.sum(segmentation * ground_truth) return (2.0 * intersection) / (np.sum(segmentation) + np.sum(ground_truth)) ``` Dice系数的取值范围为 [0, 1],值越接近1表示分割结果与真实标签越接近[^1]。 #### 2. Jaccard指数 Jaccard指数也被称为IoU(Intersection over Union),用于衡量两个集合的重叠程度。其计算公式如下: ```python def jaccard_index(segmentation, ground_truth): intersection = np.sum(segmentation * ground_truth) union = np.sum(segmentation) + np.sum(ground_truth) - intersection return intersection / union ``` Jaccard指数的取值范围同样为 [0, 1],值越大表示分割效果越好[^1]。 #### 3. Hausdorff距离 Hausdorff距离用于衡量两个点集之间的最大距离,特别适合于评估边界匹的精确度。其计算公式如下: ```python def hausdorff_distance(segmentation, ground_truth): from scipy.spatial.distance import directed_hausdorff return max(directed_hausdorff(segmentation, ground_truth)[0], directed_hausdorff(ground_truth, segmentation)[0]) ``` Hausdorff距离的值越小,表示分割结果与真实标签的边界越接近[^4]。 #### 4. 平均表面距离(ASD) 平均表面距离用于衡量分割结果与真实标签之间的平均距离,能够反映整体的边界偏差情况。其计算公式如下: ```python def average_surface_distance(segmentation, ground_truth): from scipy.spatial.distance import cdist seg_surface_points = get_surface_points(segmentation) gt_surface_points = get_surface_points(ground_truth) distances = cdist(seg_surface_points, gt_surface_points) return np.mean(np.min(distances, axis=1)) ``` 平均表面距离的值越小,表示分割结果越接近真实标签[^4]。 #### 5. 归一化互信息(NMI) 归一化互信息是一种用于衡量两个图像之间相似性的指标,常用于图像任务。其计算公式如下: ```python def normalized_mutual_information(image1, image2): hist_2d, _, _ = np.histogram2d(image1.ravel(), image2.ravel(), bins=100) pxy = hist_2d / np.sum(hist_2d) px = np.sum(pxy, axis=1) py = np.sum(pxy, axis=0) px_py = px[:, None] * py[None, :] nmi = mutual_info_score(None, None, contingency=hist_2d) return nmi ``` NMI的值越接近1,表示两幅图像的相似性越高[^2]。 #### 6. 结构相似性指数(SSIM) 结构相似性指数是一种用于衡量两幅图像之间结构相似性的指标,适用于图像和质量评估任务。其计算公式如下: ```python def structural_similarity(image1, image2): from skimage.metrics import structural_similarity as ssim return ssim(image1, image2, data_range=image2.max() - image2.min()) ``` SSIM的值越接近1,表示两幅图像的结构相似性越高[^3]。 ###
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值