A bounding box is a rectangle that localizes an object in an image. Object detection combines each box with a class label, making it possible to count, track, or crop objects without pixel-level masks. Boxes are cheaper to annotate and usually faster to process than segmentation masks. section 12.0
A COCO annotation
COCO stores each box as x, y, width, and height in pixel coordinates measured from the image’s top-left corner. For one sample, normalized boxes such as [0.12, 0.27, 0.57, 0.33] accompany labels such as cat, bench, and bicycle. Drawing these rectangles over the image makes the annotation immediately inspectable. section 12.2.1
Choose the representation according to the model or tool consuming the box:
- Prompt a segmentation model with the top-left and bottom-right corner coordinates of the rectangle. section 11.3.5
- Normalize COCO-style x, y, width, and height values to a unit square so image dimensions no longer affect manipulation. section 12.2.1
- For a YOLO grid, assign responsibility to the cell containing the box center; encode center offsets, image-relative width and height, and confidence. section 12.2.3
def to_grid(box): x, y, w, h = box cx, cy = (x + w / 2) * grid_size, (y + h / 2) * grid_size ix, iy = int(cx), int(cy) return (ix, iy), (cx - ix, cy - iy, w, h) def from_grid(loc, box): (xi, yi), (x, y, w, h) = loc, box x = (xi + x) / grid_size - w / 2 y = (yi + y) / grid_size - h / 2 return (x, y, w, h)
The conversion utilities show how to move between normalized image coordinates and YOLO grid-cell coordinates, including center offsets and reconstruction. section 12.2.3







