Bounding Boxes and Coordinates
Turn a rectangle into corner coordinates, center coordinates, dimensions, and normalized values using one worked example.
Bounding Boxes and Coordinates explained visually
Turn a rectangle into corner coordinates, center coordinates, dimensions, and normalized values using one worked example.
What you will learn
Locate objects, represent boxes, filter predictions, evaluate detections, and compare detector designs.
Read image-coordinate conventions
That rectangle around a dog looks simple. But how does a computer know exactly where to draw it?
A bounding box is usually stored as a small set of coordinates. One common format uses the top left corner and the bottom right corner. Each corner has a horizontal position and a vertical position.
In many image systems, the origin is at the top left. Moving right increases the horizontal coordinate. Moving down increases the vertical coordinate. That second direction is different from the graph you may remember from a mathematics class.
Calculate dimensions and center
Let’s use a small example. The left edge is at twenty, and the right edge is at eighty. The top edge is at ten, and the bottom edge is at fifty.
Using these edge coordinates, the width is eighty minus twenty, which is sixty. The height is fifty minus ten, which is forty. The center is halfway between the edges, at fifty horizontally and thirty vertically.
This gives us another common format: center position, width, and height. It describes the same rectangle using different numbers.
Normalize and transform boxes correctly
Some datasets store normalized coordinates. Instead of measuring directly in pixels, they divide horizontal values by the image width and vertical values by the image height.
If our image is one hundred pixels wide and one hundred pixels high, the center becomes zero point five and zero point three. The box width becomes zero point six, and its height becomes zero point four.
Normalization makes the representation relative to the image size. But it does not remove the need to transform boxes correctly when you crop, resize, or pad an image.
Check formats before comparing locations
The practical lesson is to check the format before using the numbers. Corner coordinates and center coordinates are not interchangeable. Different libraries can also use different rules for the final pixel on an edge.
Next, we’ll compare a predicted box with a reference box and measure how much they overlap.
Quick check: test your understanding
In this image-coordinate convention, which direction increases y?
Downward from the top-left origin.
What is the center/size form of (20, 10, 80, 50)?
(50, 30, 60, 40): center x, center y, width, height.
Does cropping require updating boxes?
Yes. Cropping changes the coordinate frame and may clip objects.
Accessible referenceLesson 64 transcript317 words · Matches the published narration and captionsOpen transcript
That rectangle around a dog looks simple. But how does a computer know exactly where to draw it?
A bounding box is usually stored as a small set of coordinates. One common format uses the top left corner and the bottom right corner. Each corner has a horizontal position and a vertical position.
In many image systems, the origin is at the top left. Moving right increases the horizontal coordinate. Moving down increases the vertical coordinate. That second direction is different from the graph you may remember from a mathematics class.
Let’s use a small example. The left edge is at twenty, and the right edge is at eighty. The top edge is at ten, and the bottom edge is at fifty.
Using these edge coordinates, the width is eighty minus twenty, which is sixty. The height is fifty minus ten, which is forty. The center is halfway between the edges, at fifty horizontally and thirty vertically.
This gives us another common format: center position, width, and height. It describes the same rectangle using different numbers.
Some datasets store normalized coordinates. Instead of measuring directly in pixels, they divide horizontal values by the image width and vertical values by the image height.
If our image is one hundred pixels wide and one hundred pixels high, the center becomes zero point five and zero point three. The box width becomes zero point six, and its height becomes zero point four.
Normalization makes the representation relative to the image size. But it does not remove the need to transform boxes correctly when you crop, resize, or pad an image.
The practical lesson is to check the format before using the numbers. Corner coordinates and center coordinates are not interchangeable. Different libraries can also use different rules for the final pixel on an edge.
Next, we’ll compare a predicted box with a reference box and measure how much they overlap.