边界召回率matlab代码实现
时间: 2024-05-13 11:12:32 浏览: 22
边界召回率(Boundary Recall)是一种用于评估图像分割算法性能的指标,它用于衡量图像中所有真实边界被算法正确识别的比例。Matlab代码实现如下:
```matlab
function [BR,th] = BoundaryRecall(GT,SEG)
%计算边界召回率
GT = double(GT>0);
SEG = double(SEG>0);
if sum(GT(:)) == 0
BR = NaN;
th = NaN;
return;
end
if sum(SEG(:)) == 0
BR = 0;
th = NaN;
return;
end
GTbdry = seg2bmap(GT);
SEGbdry = seg2bmap(SEG);
% compute true positives at different thresholds
n_th = 99;
range = linspace(0,1,n_th+1);
range(end) = [];
tp = zeros(n_th,1); fp = zeros(n_th,1); fn = zeros(n_th,1);
for i = 1:n_th
bmap = SEGbdry>=range(i);
tp(i) = sum(bmap(GTbdry==1));
fp(i) = sum(bmap(GTbdry==0));
fn(i) = sum(GTbdry(:))-tp(i);
end
% compute recall
recall = tp./(tp+fn);
% find best threshold
[BR,ind] = max(recall);
th = range(ind);
function E=seg2bmap(S)
% SEG2BMAP Convert a segmentation into a binary boundary map
%
% E=seg2bmap(S)
%
% INPUTS
% S - Segmentation
%
% OUTPUTS
% E - Binary boundary map
%
% EXAMPLE
%
% See also BWBOUNDARIES
%
% Piotr's Computer Vision Matlab Toolbox Version NEW
% Written and maintained by Piotr Dollar pdollar-at-gmail.com
% Please email me if you find bugs, or have suggestions or questions!
%
% Licensed under the Simplified BSD License [see external/bsd.txt]
if(ndims(S)>2), error('seg2bmap: input must be 2-D'); end
E=zeros(size(S));
E([1 end],:)=1; E(:,[1 end])=1;
if(islogical(S))
BW=bwperim(S,8);
else
BW=bwperim(S>0,8);
end
[indR indC]=find(BW); ind=sub2ind(size(S),indR,indC);
E(ind)=1;
```
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)