Computer Vision
IoU & Non-Max Suppression
IoU measures shared geometry; greedy NMS decides which scored boxes remain under an explicit overlap rule.
Pair box1, box2: overlapping. IoU is 0.06666666666666667. No object truth is supplied.
Selected A: box1 · B: box2. Lower-left anchors; x right, y up. All boxes are unverified candidates.
- Box 1 outline
- Other candidate outlines
- Selected intersection
- Move pair B anchor
- Resize pair B corner
Keep candidates with score >= floor, including equality.
- box1, index 0, score 0.9 · candidate · selected A
- box2, index 1, score 0.7 · candidate · selected B
Edit box coordinates, extents and scores
All four slots are retained in two-box mode. Finite inputs clamp/snap on commit. Negative extents are clamped to zero by this editor; the pure API rejects them.
Which corner do these coordinates locate?
These are candidate rectangles with manually assigned scores, not labelled objects or calibrated probabilities.
Bounding box
Here, a lower-left anchor plus nonnegative width and height in abstract length units.
Check this stage
Check your understanding
Inspect exact box overlap and trace greedy suppression by score, including threshold equality and original candidate identities.
Overlap is geometry, not object identity
IoU measures the fraction of two rectangles’ combined footprint that they share. NMS visits scored candidates greedily and suppresses a candidate when an already retained box overlaps it above the cut. Neither operation proves a box correct, identifies a duplicate, improves its coordinates or calibrates its score.
Start with Bounding Boxes. The encoding is (x,y,w,h): lower-left anchor, width and height. X increases rightwards and Y upwards, in abstract length units; areas use squared units. Original input indices start at zero, while identity labels start at box1. These identities survive filtering, sorting and inspection. Continuous half-open rectangles have no inclusive-pixel +1; touching edges contribute no area. This differs from conventions that count inclusive pixel endpoints.
Use the square handle to move selected pair B, or the diamond to resize its upper-right corner. Arrow keys move a focused handle in half units. Native pair selectors and the box editor supply the same operations. The original Box 2 X/Y ranges remain. The editor retains all four slots when the scene shows only two boxes. Inputs snap and clamp to their declared grids; empty/nonfinite entries are rejected. Negative editor extents clamp to zero. The pure maths API rejects negative extents/reversed endpoints, nonfinite operands and nonfinite arithmetic rather than swapping coordinates.
How is the selected pair’s IoU computed?
In Intersection over Union, predict zero, between zero and one, or one. Read the exact coordinate ledger, then reveal the result. Lower intersection bounds are the maximum of the lower coordinates; upper bounds are the minimum of the upper coordinates. Clamp each difference at zero before multiplying.
Each area is width times height. Intersection is ; union is . For positive union, . The lab defines IoU as zero when union is zero, a sentinel rather than a perfect match.
At the original defaults A=(2,3,4,4), B=(5,5,4,4), upper-right corners are (6,7) and (9,9). Intersection runs from (5,5) to (6,7): width 1, height 2, area 2. Each box has area 16, union is 16+16−2=30, and IoU is 2/30=1/15. Move B to (4,3): intersection becomes 2×4=8, union 24, IoU 1/3. Scores do not enter these equations.
Try identical positive-area rectangles (IoU one), a contained 1×1 rectangle inside a 4×4 rectangle (IoU 1/16), touching edges (zero), a gap (zero), and zero width or height (degenerate). The relation readout distinguishes these cases; degenerate takes precedence. Equal IoU does not imply equal size, location or semantic meaning. Doubling both anchors and extents multiplies both areas by four and preserves the ratio in exact arithmetic.
Which boxes does greedy NMS retain?
In Non-Max Suppression, the Score floor first removes scores strictly below the floor. Equality survives: score ≥ floor. This is confidence filtering, separate from overlap suppression.
Visit survivors by decreasing score. Exact ties use smaller original input index first. Compare each candidate with retained boxes in retention order. At the first IoU strictly greater than NMS Threshold, suppress the candidate and stop comparisons. Otherwise retain it. IoU equal to the cut survives. Coordinates and scores never change.
Step candidate completes one real decision. The completed-candidate selector revisits a deterministic prefix; it is inspection history, not training. The ledger names the current candidate, retained-before set, every comparison performed, suppression anchor and retained-after set. Inspect a decision or comparison to connect its identities to geometry and exact arithmetic. Uncompleted decisions are labelled; the complete-run output is separate. Returned indices refer to the original collection, emitted in retention order. Score-filtered, overlap-suppressed, retained and pending boxes have distinct text. Suppressed geometry remains visible; inspection does not imply retention.
For an exact boundary example, edit A=(0,0,3,2), B=(1,0,3,2). Both areas are 6, intersection 4, union 8, IoU exactly 0.5. At cut 0.5 both survive; at 0.45 the later box is suppressed; at 0.55 it survives. Hold boxes, scores, class treatment, score floor and ordering fixed while changing only the cut. Display scaling does not change the algorithm.
Choose Four boxes and load the suppression chain. Its first three rectangles share Y and size 4×4, with X at 0, 2 and 4. Neighbour IoUs are 1/3; endpoints are disjoint. With the left endpoint ranked first, both endpoints survive and the middle is suppressed. Give the middle the highest score: it suppresses both endpoints at cut 0.3. Hold geometry, score floor, class policy and suppression rule fixed; changing scores changes order and potentially the result. Exact ties follow original index.
This is greedy selection, not global optimisation. Two disjoint endpoint boxes of score 0.8 each can lose to a middle box of score 0.9, although the endpoints have larger combined score. Overlap is not transitive grouping. A suppressed candidate never becomes an anchor. A nonempty filtered candidate set always retains its first candidate; every original box can be score-filtered, but every survivor cannot be overlap-suppressed. There is no top-k or output limit.
What can this experiment establish?
The lab is class agnostic on one collection, with no labels or batch axis. Torchvision batched NMS avoids cross-category suppression. Torchvision NMS warns that equal-score selections can differ between CPU and GPU; this lab specifies input-index ties.
Distinct nearby objects can overlap. Lower cuts can suppress their boxes; higher cuts can leave duplicates. The same cut behaves differently with geometry, scores, ordering or class policies. With a fixed pair, raising the cut makes suppression less likely. Larger greedy runs can acquire different anchors, so retained sets need not be nested. No ground truth exists here to establish correctness. The original challenge asks for pair suppression under the original scores, dimensions, floor and cut, not detection success.
Quiz context extends beyond these controls: evaluation also requires class and matching rules; 3D IoU uses volumes; Soft-NMS decays scores; IoU-derived losses address geometric training objectives; DETR uses bipartite matching and set prediction training to support inference without NMS. None is a mode, training comparison or guarantee in this lab.
What does the display change?
X and Y scale independently to fit the measured canvas. Raw lengths and areas are not screen measurements. The domain covers every supported extent without clipping boxes. Intersection opacity is 0.3; filtered or prefix-suppressed outlines dim. Box 1 is solid, others dashed, with identities in native status rows. Square and diamond handles move and resize pair B. Native text and raw inspection remain readable; the SVG omits box labels instead of shrinking text. Metrics round to two decimals; exact numbers remain in the calculation and drawer. Scaling, opacity and rounding never feed back into IoU or NMS.
Mathematical edits restart the completed prefix. Pair, history, stage and sandbox edits also clear prediction; opening inspection preserves it. Earlier stages retain effective settings and display active filtering/history. Share reproduces all four slots, pair, completed prefix and displayed stage in guided mode. Guesses, sandbox identity, recovery and local progress stay local. The chain action saves the preceding experiment, including original stage, sandbox and revealed prediction; Restore experiment recovers it after further edits. Reset defaults controls at the current guided stage, enters guided and clears prediction/recovery. URL navigation also clears those snapshots. Mark explored records local exploration, not teaching acceptance.
Stage recap
Bounding Boxes
These are candidate rectangles with manually assigned scores, not labelled objects or calibrated probabilities.
Intersection over Union
Clamp each intersection dimension at zero. Divide intersection area by union area; confidence is absent from this calculation.
Non-Max Suppression
Filter scores first, then visit candidates by decreasing score and original index at ties. Compare with retained boxes; suppress only when IoU is strictly above the threshold.
Reference
- Encoding
- (x,y,w,h), lower-left, x right/y up; lengths in units, areas in squared units; no pixel +1.
- IoU
- I / (wA*hA+wB*hB−I); zero-union sentinel 0.
- NMS
- Score >= floor; decreasing score, ascending original index at ties; suppress IoU > cut. Class agnostic, no output limit.
Break it on purpose
A low threshold can suppress boxes for distinct nearby objects; a high threshold can retain duplicates. Geometry alone cannot tell which interpretation is correct.
Explore next
- Hough TransformEach point votes for possible lines; shared accumulator bins collect evidence for the same hypothesis.
- Convolution / CNNChange the filter and trace the dot product that builds each cell of the output feature map.
- Data AugmentationChange an image transform and trace which source pixels and value adjustments produce each output.