matlab中的IoU计算函数

来源:互联网 发布:免费签名设计软件 编辑:程序博客网 时间:2024/05/14 06:00

突然在代码中撇到了Faster R-CNN中的IoU计算函数,计算两个bounding box之间的IoU值。IoU计算很简单但是很常用,因为看过多次代码都没有注意过,因此记录一下。

该函数比较简单,转载自Faster R-CNN代码,作者Pedro Felzenszwalb, Ross Girshick。

function o = boxoverlap(a, b)% Compute the symmetric intersection over union overlap between a set of% bounding boxes in a and a single bounding box in b.%% a  a matrix where each row specifies a bounding box% b  a matrix where each row specifies a bounding box% AUTORIGHTS% -------------------------------------------------------% Copyright (C) 2011-2012 Ross Girshick% Copyright (C) 2008, 2009, 2010 Pedro Felzenszwalb, Ross Girshick% % This file is part of the voc-releaseX code% (http://people.cs.uchicago.edu/~rbg/latent/)% and is available under the terms of an MIT-like license% provided in COPYING. Please retain this notice and% COPYING if you use this file (or a portion of it) in% your project.% -------------------------------------------------------o = cell(1, size(b, 1));for i = 1:size(b, 1)    x1 = max(a(:,1), b(i,1));    y1 = max(a(:,2), b(i,2));    x2 = min(a(:,3), b(i,3));    y2 = min(a(:,4), b(i,4));    w = x2-x1+1;    h = y2-y1+1;    inter = w.*h;    aarea = (a(:,3)-a(:,1)+1) .* (a(:,4)-a(:,2)+1);    barea = (b(i,3)-b(i,1)+1) * (b(i,4)-b(i,2)+1);    % intersection over union overlap    o{i} = inter ./ (aarea+barea-inter);    % set invalid entries to 0 overlap    o{i}(w <= 0) = 0;    o{i}(h <= 0) = 0;endo = cell2mat(o);
0 0
原创粉丝点击