【MATLAB】评价二值分割结果的函数
根据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~=gd 12 return; 13 end 14 15 % performance by intersection-over-union 16 intersection=0; 17 unionsection=0; 18 19 for i=1:rh 20 for j=1:rw 21 if ImgResult(i,j)==fg_color && ImgGT(i,j)==fg_color 22 intersection=intersection+1; 23 end 24 if ImgResult(i,j)==fg_color || ImgGT(i,j)==fg_color 25 unionsection=unionsection+1; 26 end 27 end 28 end 29 30 if unionsection==0 31 performance=100; 32 else 33 performance=100*intersection/unionsection; 34 end 35 36 end