The most common areas of non-maxima suppression (Non Maximum suppression) are target detection, such as face detection, object detection, and so on. The following is also its application in the field of target detection and its code implementation.
The basic process for target detection is as follows:
The detailed schematic is as follows:
Therefore, in the output of the Scoremap, the number of pixels is Numel (scoremap), the output detected box is Numel (SCOREMAP), its dimension is (4,numel), then in so many output scoremap ( Detected box), which one (assuming that the image contains only one target)? This requires the elimination of redundant detbox with non-maximal values, and the process of inhibition is an iterative-traversal-cancellation process. The following code is implemented:
im = Imread (testimages{3});
im = Im2single (IM);
% Compute detections
[detections, scores] = Detect (IM, W, hogcellsize, scales);
% Non-maxima suppression
keep = boxsuppress (detections, scores, 0.25);
Detections = detections (:, keep);
Scores = scores (keep);
% further keep only top detections
detections = detections (:, 1:10);
Scores = scores (1:10);
function keep = boxsuppress (boxes, scores, threshold)
% boxsuppress Box Non-maxima suprression (non-maximum suppression)
% KEEP = Boxsuppress (BOXES, SCORES, THRESHOLD)
% Remove any empty box (Xmax < xmin or ymax < ymin)
SCORES ( [-1 0 1 0; 0-1 0 1] * Boxes < 0)) =-inf;
Keep = False (1, size (boxes,2));
While true
[score, best] = max (scores);
If score = =-inf, break; End
Keep (best) = true;
remove = boxinclusion (Boxes (:, best), boxes, ' Pascalformat ', true) >= threshold;
Scores (remove) =-inf;
Scores (best) =-inf; % ' best ' isn't in ' remove ' if threshold > 1
End
Function dist = Calcboxinclusion (A, B, Varargin)%%boxinclusion % getboxoverlap% A and B has a box for each Colu MN, in the format [xmin ymin xmax% ymax].
The resulting matrix Dist has A ' s boxes along the rows% and B ' s boxes along the columns and contains the percentage of
% the area of each box B contained in the box A.
Opts.pascalformat = false;
opts = Vl_argparse (opts, varargin);
m = size (a,2);
n = size (b,2);
O = []; If m==0 | | n==0, dist = zeros (m,n); return;
End om = ones (1,m);
on = ones (1,n);
If Opts.pascalformat a (3:4,:) = A (3:4,:) + 1; B (3:4,:) = B (3:4,:) + 1; end% find length Ox of the overlap range [x1, X2] along x% x1 cannot be smaller than a.xmin B . xmin% x2 cannot be larger than A.xmax B.xmax% Ox is x2-x1 or 0 x1 = max (A (1*on,:) ', B (1*om,:)); x2 = min (A (3*on,:)
', B (3*om,:));
Ox = max (x2-x1, 0);
Y1 = Max (A (2*on,:) ', B (2*om,:)); y2 = min (A (4*on,:) ', B (4*om,:));
Oy = max (y2-y1, 0); % is of the intersection areaint = Ox . * OY;
% area of the union is sum of areas-inersection AREAA = prod (A (3:4,:)-A (1:2,:)); Areab = prod (B (3:4,:)-B (1:2,:)); % final distance Matrix dist = areaint./(Areab (OM,:) + eps);
Note For the Focus section:
Scores (Any ([-1 0 1 0; 0-1 0 1] * Boxes < 0)) =-inf;
Note Here is the boxes format, which is [Xmin,ymin,xmax,ymax], which is multiplied with [-1 0 1 0;0-1 0 1], if its value is less than 0, that is, Xmax<xmin, ymax<ymin, this box is not valid, to be removed, is to assign the value of its corresponding score to infinity, which is not considered when the non-maximum value is suppressed.
X1 = Max (A (1*on,:) ', B (1*om,:));
x2 = Min (A (3*on,:) ', B (3*om,:));
y1 = max (A (2*on,:) ', B (2*om,:));
y2 = min (A (4*on,:) ', B (4*om,:));
To understand this piece of code, see the following figure:
The area of the overlapping portion is the area of the upper-left corner (X21,y21) (the coordinate small value of box 2) to the lower-right corner (X12,Y12) (large value of the box 1 coordinate) rectangle. Since box 1 is already detected by the larger pixel point of score, Box 2 is based on the second larger value of the box, if the two boxes have a large area coincident (set a threshold), it can be explained that box 1 and box 2 are near the target, but box 1 is more accurate point to target, Then box 2 is not necessary to keep. Continue iterating over the next detected box, whether or not it satisfies the elimination criteria to decide whether to preserve box, which is non-maximum suppression.
Reference:
1. nms--non-maximal value suppression