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