Bounding Box Representations
What You'll Learn
You'll learn the two most common ways to represent bounding boxes in object detection and how to convert between them.
The Core Idea
When detecting objects in images, we need a mathematical way to describe rectangular boxes around them. Think of drawing a rectangle on a photo to highlight where a car or person appears—but instead of physically drawing, we need numbers that a computer can work with.
There are two standard representations:
1. Center-Width-Height Format (x, y, w, h)
x, y: The center point coordinates of the boxw: Width of the boxh: Height of the box
Example: (100, 150, 50, 80) means a box centered at pixel (100, 150), 50 pixels wide and 80 pixels tall.
2. Corner Format (x1, y1, x2, y2)
x1, y1: Top-left corner coordinatesx2, y2: Bottom-right corner coordinates
Example: (75, 110, 125, 190) means a box from top-left (75, 110) to bottom-right (125, 190).
Converting Between Formats
From (x, y, w, h) to (x1, y1, x2, y2):
x1 = x - w/2y1 = y - h/2x2 = x + w/2y2 = y + h/2
From (x1, y1, x2, y2) to (x, y, w, h):
x = (x1 + x2) / 2y = (y1 + y2) / 2w = x2 - x1h = y2 - y1
Different detection algorithms prefer different formats—YOLO uses center format while R-CNN uses corner format—so knowing both is essential.
Key Takeaway: Bounding boxes can be represented as center-width-height (x, y, w, h) or as opposite corners (x1, y1, x2, y2), and you can convert between them using simple arithmetic based on the relationship between center points, dimensions, and corners.