【MATLAB】评价二值分割结果的函数

时间:2023-03-09 02:24:42
【MATLAB】评价二值分割结果的函数

根据PASCAL challenges的标准:intersection-over-union score,所写的matlab评价程序,处理二值图像。

其思想即分割结果与Ground Trueth的交集比上它们的并集,即为分割的准确率,代码如下:

 function performance =get_performance_iou_binary(ImgResult, ImgGT)

 % background color & foreground
bg_color = ;
fg_color = ; % check the size
[rh rw rd] = size(ImgResult);
[gh gw gd] = size(ImgGT); if rh~=gh || rw~=gw || rd~=gd
return;
end % performance by intersection-over-union
intersection=;
unionsection=; for i=:rh
for j=:rw
if ImgResult(i,j)==fg_color && ImgGT(i,j)==fg_color
intersection=intersection+;
end
if ImgResult(i,j)==fg_color || ImgGT(i,j)==fg_color
unionsection=unionsection+;
end
end
end if unionsection==
performance=;
else
performance=*intersection/unionsection;
end end