非极大值抑制(Non-maximum suppression, NMS)

算法本质

搜索局部最大值,而抑制非极大值元素。

例子

3邻域请款下的NMS算法的实现过程,即找到相邻3个元素中中间最大的元素。
数学表达式:
数组 arr[1,w] ,存在 1<i<w 使得如下公式成立:

arr[i1]<=arr[i]>arr[i+1]

i <script type="math/tex" id="MathJax-Element-195">i</script>为1个非极大值抑制点

NMS在物体检测中的应用

目标检测过程中为了消除多余的窗口, 找到最佳的目标检测位置。、
这里写图片描述
这里写图片描述

MATLAB 代码

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值