根据PASCAL challenges的标准:intersection-over-union score,所写的matlab评价程序,处理二值图像。
其思想即分割结果与Ground Trueth的交集比上它们的并集,即为分割的准确率,代码如下:
1 function performance =get_performance_iou_binary(ImgResult, ImgGT) 2 3 % background color & foreground 4 bg_color = 0 ; 5 fg_color = 255 ; 6 7 % check the size 8 [rh rw rd] = size(ImgResult); 9 [gh gw gd] = size(ImgGT);10 11 if rh~=gh || rw~=gw || rd~=gd12 return;13 end14 15 % performance by intersection-over-union16 intersection=0;17 unionsection=0;18 19 for i=1:rh20 for j=1:rw21 if ImgResult(i,j)==fg_color && ImgGT(i,j)==fg_color22 intersection=intersection+1;23 end24 if ImgResult(i,j)==fg_color || ImgGT(i,j)==fg_color25 unionsection=unionsection+1;26 end27 end28 end29 30 if unionsection==031 performance=100;32 else33 performance=100*intersection/unionsection;34 end35 36 end