对眼底图像血管分割结果求Dice系数

  • 首先将预测的图片转换为二值图如下:to_binary.py
import cv2
import os
import numpy as npif __name__ == '__main__':path = 'xxx/'imgdir = os.listdir(path)for v in imgdir:img = cv2.imread(path + v)print(img.shape)img = (img >= 100)*255cv2.imwrite('binaried/' + str(v), img)
  • 求Dice系数:dice=2*(A∩B)/(A+B)
import numpy as np
import os
import cv2
from PIL import Imageif __name__ == '__main__':y_true_path = '1st_manual/'y_pred_path = 'binaried/'dice_list = []for i in range(20):y_true = np.array(Image.open(y_true_path+str(i+1)+'_manual1.gif'))#注意cv2不能打开gif格式的图片y_pred = cv2.imread(y_pred_path+str(i+1)+'.png',cv2.IMREAD_GRAYSCALE)y_true = y_true/255y_pred = y_pred/255union = y_true * y_preddice = 2*np.sum(union)/(np.sum(y_true)+np.sum(y_pred))dice_list.append(dice)print(dice_list)print(np.mean(np.array(dice_list)))


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部