图像分割评价指标模型总结

转载自GeekZW







                **转载自  https://blog.csdn.net/zichen_ziqi/article/details/80408465**                 

                                    机器学习&图像分割——模型评价总结(含完整代码)


  • 模型评价的方法指标有很多,如:PR-curve,MAE,ROC,Precision,Recall,AUC,AP,mAP,DSI,VOE,RVD等等;
  • 本文旨在介绍机器学习&图像分割的模型评价指标,包括完整代码,持续更新中......
  • 码字不易,若有帮助,恳请点赞,?????????

问题1:在显著性检测方面,假设现有三种方法(DSR,GMA,MCA)检测标准数据库中的部分图像(还有原图与真值图),分别得到三种结果,如何求三种方法与真值图之间的MAE(平均绝对误差),并绘制PR-curve曲线图呢?

(1)image原图

(2)mask图像 (ground truth,真值图)

(3)resultsDSR图像

(4)resultsGMA图像

(5)resultsMCA图像

文件夹内容如下图,链接:https://pan.baidu.com/s/1Wg_necXBCYsCk7pf2s7gog 或PR-curve绘制,密码:lka7

输出结果为:

具体实现——Matlab代码如下:


 
 
  1. clear all;clc;close all;
  2. addpath( 'Functions\');%加载文件夹Functions中的函数
  3. %% 三种方法得到的结果路径,以及真值图路径
  4. result1 = 'resultsDSR\';
  5. result2 = 'resultsMCA\';
  6. result3 = 'resultsGMR\';
  7. mask = 'mask\';
  8. %% 创建文件夹evaluation index,目的是保存PR曲线图
  9. newFolder = 'evaluation index';
  10. if ~exist(newFolder)
  11. mkdir(newFolder);
  12. end
  13. %% Evaluation index 1: evaluating MAE
  14. resultSuffixDSR = '_DSR.png';
  15. resultSuffixMCA = '_MCA.png';
  16. resultSuffixGMR = '_stage1.png';
  17. gtSuffix = '.png';
  18. maeDSR = CalMeanMAE(result1, resultSuffixDSR, mask, gtSuffix);
  19. maeMCA = CalMeanMAE(result2, resultSuffixMCA, mask, gtSuffix);
  20. maeGMR = CalMeanMAE(result3, resultSuffixGMR, mask, gtSuffix);
  21. %% Evaluation index 2: ploting PR curve
  22. [rec1, prec1] = DrawPRCurve(result1, resultSuffixDSR, mask, gtSuffix, true, true, 'r');
  23. hold on
  24. [rec2, prec2] = DrawPRCurve(result2, resultSuffixMCA, mask, gtSuffix, true, true, 'g');
  25. hold on
  26. [rec3, prec3] = DrawPRCurve(result3, resultSuffixGMR, mask, gtSuffix, true, true, 'b');
  27. hold off;
  28. grid on;
  29. box on;
  30. xlabel( 'Recall');
  31. ylabel( 'Precision');
  32. % title(strcat( 'PR-curve', ' ( ',sprintf( ' MAE = %1.6f ',maeDSR), ' )'));
  33. title( 'PR-curve');
  34. lg = legend({ 'DSR method', 'CA method', 'GMR method'});
  35. set(lg, 'location', 'southwest');
  36. k=1.2;
  37. set(gcf, 'units',get(gcf, 'paperunits'));
  38. set(gcf, 'paperposition',get(gcf, 'position')*k);
  39. saveas(gcf,strcat(newFolder, '\PR-curve', '.bmp'));

 

问题2:医学图像分割领域中的模型评价指标总结

强烈建议参照以下两篇文章:

Performance measure characterization for evaluating neuroimage segmentation algorithms

Metrics for evaluating 3D medical imagesegmentation: analysis, selection, and tool

度量指标分析工具github:https://github.com/Visceral-Project/EvaluateSegmentation

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

符号定义:

         :  代表 ground truth的分割结果

         :代表预测的分割结果

(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定义比较类似,只不过把计算平均的操作替换成了计算最大值的操作。其数学定义为:

参照博客:图像分割评价标准。具体代码见链接:https://pan.baidu.com/s/1C7BWIebYbE4EJIoGKtjLSA,密码是:gjlb,内容如下:

(一)Matlab 具体的代码实现如下:

主函数demo:


 
 
  1. clc;clear all;close all;
  2. %% step 1:读入图像
  3. SEG = imread( '0009_CHS.png'); % 读入分割图像
  4. GT = imread( '0009.png'); % 读入真值图像
  5. %% step 2:灰度化
  6. if (length(size(SEG))> 2 && length(size(GT))> 2)
  7. SEG = im2gray(SEG); % 灰度化分割图像
  8. GT = im2gray(GT); % 灰度化真值图像
  9. end
  10. %% step 3:二值化
  11. SEG = imbinarize(SEG); % 二值化分割图像
  12. GT = imbinarize(GT); % 二值化真值图像
  13. %% step 4:画图预览
  14. figure( 1),
  15. subplot( 121),imshow(SEG);
  16. title( '二值化后的分割图像');
  17. subplot( 122),imshow(GT);
  18. title( '二值化后的真值图像');
  19. %% step 5:计算各个评价指标
  20. % ( 1)计算DICE系数
  21. DSI = calDSI(SEG, GT);
  22. fprintf( '(1) DICE系数: DSI = %.4f\n',DSI);
  23. % ( 2)计算VOE系数
  24. VOE = calVOE(SEG, GT);
  25. fprintf( '(2) VOE系数: VOE = %.4f\n',VOE);
  26. % ( 3)计算RVD系数
  27. RVD = calRVD(SEG, GT);
  28. fprintf( '(3) RVD系数: RVD = %.4f\n',RVD);
  29. % ( 4)计算Precision系数
  30. Precision = calPrecision(SEG, GT);
  31. fprintf( '(4) Precision系数: Precision = %.4f\n',Precision);
  32. %( 5)计算Recall系数
  33. Recall = calRecall(SEG, GT);
  34. fprintf( '(5) Recall系数: Recall = %.4f\n\n\n',Recall);
  35. disp( '其他评价指标的计算');
  36. % ( 6)其他评价指标的计算
  37. jaccard = Jaccard_Index(SEG, GT)
  38. sensitivity = getSensitivity(SEG, GT)
  39. hd = Hausdorff_Dist(SEG, GT)
  40. apd = Avg_PerpenDist(SEG, GT)
  41. confm_index = ConformityCoefficient(SEG, GT)

先看运行结果:

 

 其中调用函数文件分别为:

(a)calDSI函数文件:


 
 
  1. function DSI = calDSI(SEG, GT)
  2. % SEG, GT are the binary segmentation and ground truth areas, respectively.
  3. % 计算DICE系数,即DSI
  4. DSI = 2*double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(SEG(:))) + sum(uint8(GT(:))));
  5. end

(b) calVOE函数文件:


 
 
  1. function VOE = calVOE(SEG, GT)
  2. % SEG, GT are the binary segmentation and ground truth areas, respectively.
  3. % 计算VOE系数,即VOE
  4. VOE = 2*double(sum(uint8(SEG(:))) - sum(uint8(GT(:)))) / double(sum(uint8(SEG(:))) + sum(uint8(GT(:))));
  5. end

(c) calRVD函数文件:


 
 
  1. function RVD = calRVD(SEG, GT)
  2. % SEG, GT are the binary segmentation and ground truth areas, respectively.
  3. % 计算RVD系数,即RVD
  4. RVD = double(sum(uint8(SEG(:))) ) / double(sum(uint8(GT(:)))) - 1;
  5. end

(d) calPrecision函数文件:


 
 
  1. function precision = calPrecision(SEG, GT)
  2. % SEG, GT are the binary segmentation and ground truth areas, respectively.
  3. % precision
  4. precision = double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(SEG(:))));
  5. end

(e) calRecall函数文件:


 
 
  1. function recall = calRecall(SEG, GT)
  2. % SEG, GT are the binary segmentation and ground truth areas, respectively.
  3. % recall
  4. recall = double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(GT(:))));
  5. end

 (f) 其他指标的函数文件见以上链接。

(二)Python代码如下:


 
 
  1. import cv2
  2. from matplotlib import pyplot as plt
  3. # 计算DICE系数,即DSI
  4. def calDSI(binary_GT,binary_R):
  5. row, col = binary_GT.shape # 矩阵的行与列
  6. DSI_s,DSI_t = 0, 0
  7. for i in range(row):
  8. for j in range(col):
  9. if binary_GT[i][j] == 255 and binary_R[i][j] == 255:
  10. DSI_s += 1
  11. if binary_GT[i][j] == 255:
  12. DSI_t += 1
  13. if binary_R[i][j] == 255:
  14. DSI_t += 1
  15. DSI = 2*DSI_s/DSI_t
  16. # print(DSI)
  17. return DSI
  18. # 计算VOE系数,即VOE
  19. def calVOE(binary_GT,binary_R):
  20. row, col = binary_GT.shape # 矩阵的行与列
  21. VOE_s,VOE_t = 0, 0
  22. for i in range(row):
  23. for j in range(col):
  24. if binary_GT[i][j] == 255:
  25. VOE_s += 1
  26. if binary_R[i][j] == 255:
  27. VOE_t += 1
  28. VOE = 2*(VOE_t - VOE_s)/(VOE_t + VOE_s)
  29. return VOE
  30. # 计算RVD系数,即RVD
  31. def calRVD(binary_GT,binary_R):
  32. row, col = binary_GT.shape # 矩阵的行与列
  33. RVD_s,RVD_t = 0, 0
  34. for i in range(row):
  35. for j in range(col):
  36. if binary_GT[i][j] == 255:
  37. RVD_s += 1
  38. if binary_R[i][j] == 255:
  39. RVD_t += 1
  40. RVD = RVD_t/RVD_s - 1
  41. return RVD
  42. # 计算Prevision系数,即Precison
  43. def calPrecision(binary_GT,binary_R):
  44. row, col = binary_GT.shape # 矩阵的行与列
  45. P_s,P_t = 0, 0
  46. for i in range(row):
  47. for j in range(col):
  48. if binary_GT[i][j] == 255 and binary_R[i][j] == 255:
  49. P_s += 1
  50. if binary_R[i][j] == 255:
  51. P_t += 1
  52. Precision = P_s/P_t
  53. return Precision
  54. # 计算Recall系数,即Recall
  55. def calRecall(binary_GT,binary_R):
  56. row, col = binary_GT.shape # 矩阵的行与列
  57. R_s,R_t = 0, 0
  58. for i in range(row):
  59. for j in range(col):
  60. if binary_GT[i][j] == 255 and binary_R[i][j] == 255:
  61. R_s += 1
  62. if binary_GT[i][j] == 255:
  63. R_t += 1
  64. Recall = R_s/R_t
  65. return Recall
  66. if __name__ == '__main__':
  67. # step 1:读入图像,并灰度化
  68. img_GT = cv2.imread( '0009.png', 0)
  69. img_R = cv2.imread( '0009_CHS.png', 0)
  70. # imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # 灰度化
  71. # img_GT = img_GT[:,:,[2, 1, 0]]
  72. # img_R = img_R[:,: [2, 1, 0]]
  73. # step2:二值化
  74. # 利用大律法,全局自适应阈值 参数0可改为任意数字但不起作用
  75. ret_GT, binary_GT = cv2.threshold(img_GT, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  76. ret_R, binary_R = cv2.threshold(img_R, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  77. # step 3: 显示二值化后的分割图像与真值图像
  78. plt.figure()
  79. plt.subplot( 121),plt.imshow(binary_GT),plt.title( '真值图')
  80. plt.axis( 'off')
  81. plt.subplot( 122),plt.imshow(binary_R),plt.title( '分割图')
  82. plt.axis( 'off')
  83. plt.show()
  84. # step 4:计算DSI
  85. print( '(1)DICE计算结果, DSI = {0:.4}'.format(calDSI(binary_GT,binary_R))) # 保留四位有效数字
  86. # step 5:计算VOE
  87. print( '(2)VOE计算结果, VOE = {0:.4}'.format(calVOE(binary_GT,binary_R)))
  88. # step 6:计算RVD
  89. print( '(3)RVD计算结果, RVD = {0:.4}'.format(calRVD(binary_GT,binary_R)))
  90. # step 7:计算Precision
  91. print( '(4)Precision计算结果, Precision = {0:.4}'.format(calPrecision(binary_GT,binary_R)))
  92. # step 8:计算Recall
  93. print( '(5)Recall计算结果, Recall = {0:.4}'.format(calRecall(binary_GT,binary_R)))

运行结果:

 

2、分割精度、过分割率、欠分割率的定义

(1)分割精度:分割准确的面积占GT图像中真实面积的百分比,数学定义如下:

      其中表示专家手工勾画出的分割图像的参考面积,表示算法分割得到的图像的真实面积,表示错误分割的像素点个数。

(2)过分割率:即分割在GT图像参考面积之外的像素点的比率,数学定义如下

        其中表示本不应该包含在分割结果中的像素点个数,实际却在分割结果中的像素点个数。换句话讲,中的像素点出现在实际分割图像中,但不出现在理论分割图像中。

(3)欠分割率:即分割在GT图像参考面积之中欠缺的像素点的比率,数学定义如下:

       其中表示本应该包含在分割结果中的像素点个数,实际却不在分割结果中的像素点个数。换句话讲,中的像素点出现在理论分割图像中,但不出现在实际分割图像中。

 

3、灵敏度与特异度的定义

假设实验图像为I,真实分割结果为G,实际分割结果为R。

(1)灵敏度:将实际是感兴趣区域的像素点正确地判断为感兴趣区域像素的比例,其衡量的是分割实验中能分割感兴趣区域的能力,其数学定义如下。

(1)特异度:将实际不是感兴趣区域的像素点正确地判断为不是感兴趣区域像素的比例,其衡量的是分割实验中能正确判断不是感兴趣区域像素点的能力,其数学定义如下。

Matlab的灵敏度函数:


 
 
  1. function sen = getSensitivity(SEG, GT)
  2. % SEG, GT are the binary segmentation and ground truth areas, respectively.
  3. % sensitivity
  4. sen = double(sum(uint8(SEG(:) & GT(:)))) / double(sum(uint8(SEG(:))));
  5. end

 

参考网址:

1、如何在CSDN博客插入公式:http://private.codecogs.com/latex/eqneditor.php

2、图像分割结果评价:https://blog.csdn.net/zhuason/article/details/52989091

3、图像分割评价标准代码https://blog.csdn.net/yangyangyang20092010/article/details/51637073

  • 10
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 对于图像分割评价指标,常用的有类别像素准确率(CPA)、准确率(Accuracy)和交并比(IoU)。 类别像素准确率是指预测类别正确的像素数占类别总像素数的比例,也称为召回率。其计算方式可以使用以下Python代码: ```python def per_class_PA_Recall(hist): return np.diag(hist) / np.maximum(hist.sum(1), 1) ``` 准确率是指预测正确的样本数占总样本数的比例,也就是类别像素准确率的均值。计算方式如下: ```python def per_Accuracy(hist): return np.sum(np.diag(hist)) / np.maximum(np.sum(hist), 1) ``` 交并比表示的是模型对某一类别预测结果和真实值的交集与并集的比值。对于图像分割,可以计算预测掩码和真实掩码之间的交并比。可以使用以下代码实现: ```python def per_class_iu(hist): return np.diag(hist) / np.maximum((hist.sum(1) + hist.sum(0) - np.diag(hist)), 1) ``` 以上是常用的图像分割评价指标的计算方法。可以根据需要使用这些代码来评估模型图像分割任务中的性能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [图像分割常见性能指标的计算方法(python)](https://blog.csdn.net/weixin_47057808/article/details/129702149)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值