NMS (non maximum suppression), Chinese name non-maximal value suppression, in many computer vision tasks are widely used, such as: edge detection, target detection and so on.
In this paper, the application of face detection is used as an example to illustrate the NMS, and the MATLAB and C + + sample programs are given.
Some concepts of human face detection
(1) Most of the face detector is the core of the classifier, that is, given a fixed size image, classifier judge is or not human face;
(2) the key to convert the classifier into a detector is to generate a window from multiple scales on the original image and resize it to a fixed size, and then give the classifier a judgment. The most common method is to slide the window.
In the following diagram, for example, the same person may have several boxes (each with a classifier score) due to sliding windows.
And our goal is to keep only one optimal box for one person:
so we're going to use non-maxima suppression to suppress those redundant boxes: The process of suppressing is an iterative-traversal-elimination process.
(1) sort the score of all boxes, select the highest score and the corresponding box:
(2) traverse the rest of the boxes, and if the overlap area (IOU) is greater than a certain threshold, we will delete the box.
(3) continue to select one of the highest scores in the box that has never been processed and repeat the process.
The following is a quick NMS code under MATLAB with detailed comments:
Percent Nms:non maximum suppression function pick = NMS (boxes,threshold,type)% boxes:m x 5, denoted by M box, 5 columns respectively [x1 y1 x2 y2 score]%
Threshold:iou threshold% Type:iou threshold value defined type% input is empty, then directly returns if IsEmpty (boxes) pick = [];
Return
End% out the upper-left and lower-right coordinates and the classifier score (confidence) x1 = Boxes (:, 1);
Y1 = boxes (:, 2);
x2 = Boxes (:, 3);
y2 = boxes (:, 4);
s = Boxes (:, 5);
The area of each box is calculated by the square = (x2-x1+1). * (y2-y1+1);
% will be scored in ascending order [Vals, I] = sort (s);
% initialization pick = s*0;
counter = 1; % Loop until all box processing is complete while ~isempty (i) last = length (i);
% of the current number of remaining boxes i = i (last);% Select the final, that is, the highest scoring box pick (counter) = i;
Counter = counter + 1;
% calculates the intersection area 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; % IOU If strcmp under different definitions (TyPE, ' min ')% overlap area and minimum box area ratio o = Inter./min (Areas (i), areas (I (1:last-1)));
Else% intersection/set o = Inter./(Area (i) + Area (I (1:last-1))-Inter);
End% keeps all overlapping areas less than the threshold box, leaving the next processing i = I (Find (o<=threshold));
End pick = pick (1: (counter-1)); End