Overlap area between two bounding boxes
4 views (last 30 days)
Show older comments
Hi, I need to calculate the overlap area between two bounding boxes in my object detection task to evaluate detection accuracy. I have the following code but I don't know which one is correct. Two different codes have different results. Could someone ask me which one is useful?
%% The following is the first one
Suppose the ground truth bounding box is gt=[x_g,y_g,width_g,height_g] and the predicted bounding box is pr=[x_p,y_p,width_p,height_p] then the area of overlap can be calculated using the formula:
intersectionArea=rectint(gt,pr);
unionCoords=[min(x_g,x_p),min(y_g,y_p),max(x_g+width_g-1,x_p+width_p-1),max(y_g+height_g-1,y_p+height_p-1];
unionArea=(unionCoords(3)-unionCoords(1)+1)*(unionCoords(4)-unionCoords(2)+1);
overlapArea=intersectionArea/unionArea; %This should be greater than 0.5 to consider it as a valid detection.
%%The following is the second one
Overlarea=area(intersect(gt,pr))/area(union(gt,pr))
0 Comments
Answers (1)
Image Analyst
on 10 Jun 2014
If they're different, then only one is right. I'd pick the one that give you the "correct" answer based on what you know from simple algebra. Discard the one with the different, wrong answer.
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!