matlab 非极大值抑制,非极大值抑制算法(matlab实现)

参考:http://www.cnblogs.com/liekkas0626/p/5219244.html

884d9e64a287a8d95dcff79c6153b5dd.png

function pickLocate = nms(boxes, overlap)

% Non-maximum suppression.

% In object detect algorithm, select high score detections and skip windows

% covered by a previously selected detection.

%

% input - boxes : object detect windows.

% xMin yMin xMax yMax score.

% overlap : suppression threshold.

% output - pickLocate : number of local maximum score.

boxes = double(boxes);

if isempty(boxes)

pickLocate = [];

else

xMin = boxes(:, 1);

yMin = boxes(:, 2);

xMax = boxes(:, 3);

yMax = boxes(:, 4);

s = boxes(:, end);

% area of every detected windows.

area = (xMax - xMin + 1) .* (yMax - yMin + 1);

% sort detected windows based on the score.

[vals, I] = sort(s);

pickLocate = [];

while ~isempty(I)

last = length(I);

i = I(last);

pickLocate = [pickLocate; i];

suppress = [last];

for pos = 1 : last - 1

j = I(pos);

% covered area.

xx1 = max(xMin(i), xMin(j));

yy1 = max(yMin(i), yMin(j));

xx2 = min(xMax(i), xMax(j));

yy2 = min(yMax(i), yMax(j));

w = xx2 - xx1 + 1;

h = yy2 - yy1 + 1;

if ((w > 0) && (h > 0))

% compute overlap.

o = w * h / min(area(i), area(j));

if (o > overlap)

suppress = [suppress; pos];

end

end

% xx1 = max(x1(i), x1(I(1:last-1)));

% yy1 = max(y1(i), y1(I(1:last-1)));

% xx2 = min(x2(i), x2(I(1:last-1)));

% yy2 = min(y2(i), y2(I(1:last-1)));

% w = max(0.0, xx2-xx1+1);

% h = max(0.0, yy2-yy1+1);

% inter = w.*h;

% o = inter ./ (area(i) + area(I(1:last-1)) - inter);

% saving the windows which o less than threshold.

% I = I(o <= overlap);

end

I(suppress) = [];

end

end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值