A bounding box describes a rectangular region of an image. Four numbers are enough for an axis-aligned box, but those numbers are meaningful only when the format, units, and image dimensions are known. A format mismatch can turn a plausible detection into a box drawn in the wrong place.
Keep the rectangle fixed while changing its description
The explorer starts with a box around the left car. Change the format without moving the rectangle, then switch between pixel and normalized coordinates. All views describe the same boundaries.
- x₁
- 30.0
- y₁
- 100.0
- x₂
- 120.0
- y₂
- 160.0
Image size: 320 × 200. The origin is at the top left; x increases right and y increases down. These are continuous boundary coordinates, so the right boundary may equal 320.
The image is 320 pixels wide and 200 pixels high. Its origin is at the top left, with x increasing rightward and y increasing downward. The box initially spans (30, 100) to (120, 160).
Three common formats
| Format | Values for the starting box | Meaning |
|---|---|---|
xyxy | (30, 100, 120, 160) | Left, top, right, bottom |
xywh | (30, 100, 90, 60) | Left, top, width, height |
cxcywh | (75, 130, 90, 60) | Center x, center y, width, height |
The conversion follows directly from the geometry:
To recover corners from center-size form, subtract and add half the width and height. Torchvision provides explicit conversion utilities; passing the correct input format is part of their contract. Torchvision box conversion
Normalize x by width and y by height
For normalized coordinates, divide horizontal values by image width and vertical values by image height. The starting xyxy box becomes (0.09375, 0.5, 0.375, 0.8). Using width for all four values would make the vertical coordinates wrong on this rectangular image.
Normalization does not make a box independent of preprocessing. A center crop removes an offset before scaling; letterboxing adds padding after scaling. The coordinate values still refer to a particular image canvas. Record whether labels describe the original image, the resized image, or the padded model input.
Boundaries are different from pixel indices
This page uses continuous image-boundary coordinates. A full-image box is (0, 0, 320, 200), with area 320 × 200. Although the last pixel column has index 319, its right boundary is 320. There is no extra +1 in this area calculation.
Some older annotation or evaluation conventions use inclusive integer endpoints. Do not mix their area formulas with continuous boundaries. A one-pixel discrepancy matters especially for tiny objects, where a small coordinate error can change a large fraction of the box area.
Transform and validate labels with the image
For a horizontal flip across a canvas of width , corners transform as:
The left and right roles exchange. Flipping each x value without exchanging them creates negative width. After a crop, subtract the crop origin, clip to the retained canvas, and remove boxes whose clipped width or height is zero. Keep class labels and any object IDs aligned with the surviving boxes.
Inspect transformed annotations visually before training. Check positive dimensions, finite numbers, the expected coordinate range, and the same transform for every label type. Augmentation demonstrates this correspondence; IoU uses the resulting geometry to measure overlap.
Related concepts
Learn how normalized box coordinates, L1 loss, IoU, and Generalized IoU guide object localization, including disjoint boxes and containment limits.
Calculate box intersection and union, explore how position and size change IoU, and distinguish overlap used for evaluation, NMS and localization losses.
Understand object detection from image features to boxes, classes and scores. Compare one-stage and two-stage pipelines, training and duplicate handling.
Compare anchor-based vs anchor-free object detection: Faster R-CNN and RetinaNet anchors vs FCOS and CenterNet point-based methods.
Learn how DETR assigns unordered object targets to prediction slots, why greedy choices can fail, and how matching differs from training loss and evaluation.
Follow a query from a spatial reference through learned offsets, bilinear feature sampling and weighted aggregation, with exact non-square coordinate arithmetic.
