Pytorch 图像分割 衡量标准

本文详细介绍了医学图像比赛中常用的评估指标,包括DICE、VOE、RVD、ASD和MSD等,并提供了这些指标的数学定义及编程实现方法。通过具体的Python代码示例,展示了如何计算DICE系数、VOE系数、RVD系数、Precision系数和Recall系数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、医学图像比赛(ISBI2017或者MICCAI2007)中常用到的几个度量指标:DICE,VOE,RVD,ASD,MSD等等;如何编程实现?

符号定义:

     Rgt:  代表 ground truth的分割结果

     Rseg:代表预测的分割结果

(1)DICE(值域为[0,1]): 使用频率最高。数学定义如下,具体表示两个物体相交的面积占总面积的比值,完美分割该值为1。

(2)VOE(volumetric overlap error): 与DICE类似,数学定义如下,它将and操作换成了减法操作,以此来代表错误率。

(3)RVD(relative volume difference):表示两者体积之间的差异,数学定义如下。

(4)ASD(average symmetric surface distance): 先定义 代表的是预测的中的边界的像素,同样地可以得到的定义。然后对的定义,同理可得的定义。那么ASD的数学定义为:

(5)MSD(maximum symmetric surface distance):与ASD定义比较类似,只不过把计算平均的操作替换成了计算最大值的操作。其数学定义为:
在这里插入图片描述

import cv2
from matplotlib import pyplot as plt
 
 
# 计算DICE系数,即DSI
def calDSI(binary_GT,binary_R):
    row, col = binary_GT.shape  # 矩阵的行与列
    DSI_s,DSI_t = 0,0
    for i in range(row):
        for j in range(col):
            if binary_GT[i][j] == 255 and binary_R[i][j] == 255:
                DSI_s += 1
            if binary_GT[i][j] == 255:
                DSI_t += 1
            if binary_R[i][j]  == 255:
                DSI_t += 1
    DSI = 2*DSI_s/DSI_t
    # print(DSI)
    return DSI
 
# 计算VOE系数,即VOE
def calVOE(binary_GT,binary_R):
    row, col = binary_GT.shape  # 矩阵的行与列
    VOE_s,VOE_t = 0,0
    for i in range(row):
        for j in range(col):
            if binary_GT[i][j] == 255:
                VOE_s += 1
            if binary_R[i][j]  == 255:
                VOE_t += 1
    VOE = 2*(VOE_t - VOE_s)/(VOE_t + VOE_s)
    return VOE
 
# 计算RVD系数,即RVD
def calRVD(binary_GT,binary_R):
    row, col = binary_GT.shape  # 矩阵的行与列
    RVD_s,RVD_t = 0,0
    for i in range(row):
        for j in range(col):
            if binary_GT[i][j] == 255:
                RVD_s += 1
            if binary_R[i][j]  == 255:
                RVD_t += 1
    RVD = RVD_t/RVD_s - 1
    return RVD
 
# 计算Prevision系数,即Precison
def calPrecision(binary_GT,binary_R):
    row, col = binary_GT.shape  # 矩阵的行与列
    P_s,P_t = 0,0
    for i in range(row):
        for j in range(col):
            if binary_GT[i][j] == 255 and binary_R[i][j] == 255:
                P_s += 1
            if binary_R[i][j]   == 255:
                P_t += 1
 
    Precision = P_s/P_t
    return Precision
 
# 计算Recall系数,即Recall
def calRecall(binary_GT,binary_R):
    row, col = binary_GT.shape  # 矩阵的行与列
    R_s,R_t = 0,0
    for i in range(row):
        for j in range(col):
            if binary_GT[i][j] == 255 and binary_R[i][j] == 255:
                R_s += 1
            if binary_GT[i][j]   == 255:
                R_t += 1
 
    Recall = R_s/R_t
    return Recall
 
 
 
if __name__ == '__main__':
    # step 1:读入图像,并灰度化
    img_GT = cv2.imread('0009.png',0)
    img_R  = cv2.imread('0009_CHS.png',0)
    # imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)   # 灰度化
    # img_GT = img_GT[:,:,[2, 1, 0]]
    # img_R  = img_R[:,: [2, 1, 0]]
 
    # step2:二值化
    # 利用大律法,全局自适应阈值 参数0可改为任意数字但不起作用
    ret_GT, binary_GT = cv2.threshold(img_GT, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
    ret_R, binary_R   = cv2.threshold(img_R, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
 
    # step 3: 显示二值化后的分割图像与真值图像
    plt.figure()
    plt.subplot(121),plt.imshow(binary_GT),plt.title('真值图')
    plt.axis('off')
    plt.subplot(122),plt.imshow(binary_R),plt.title('分割图')
    plt.axis('off')
    plt.show()
 
 
    # step 4:计算DSI
    print('(1)DICE计算结果,      DSI       = {0:.4}'.format(calDSI(binary_GT,binary_R)))  # 保留四位有效数字
 
    # step 5:计算VOE
    print('(2)VOE计算结果,       VOE       = {0:.4}'.format(calVOE(binary_GT,binary_R)))
 
    # step 6:计算RVD
    print('(3)RVD计算结果,       RVD       = {0:.4}'.format(calRVD(binary_GT,binary_R)))
 
    # step 7:计算Precision
    print('(4)Precision计算结果, Precision = {0:.4}'.format(calPrecision(binary_GT,binary_R)))
 
    # step 8:计算Recall
    print('(5)Recall计算结果,    Recall    = {0:.4}'.format(calRecall(binary_GT,binary_R)))

原文链接:https://blog.csdn.net/zichen_ziqi/article/details/80408465

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值