Concept

Bounding Box Format Conversion

It is often necessary to convert bounding box coordinates between the two-corner format and the center-width-height format. Computationally, bounding boxes are processed as a two-dimensional tensor of shape (n,4)(n, 4), where nn is the number of bounding boxes. To convert from the two-corner representation to the center-width-height representation, the center coordinates are calculated by finding the midpoint between the upper-left (x1,y1)(x_1, y_1) and lower-right (x2,y2)(x_2, y_2) corners, and the dimensions are determined by taking the coordinate differences: cx=(x1+x2)/2c_x = (x_1 + x_2) / 2, cy=(y1+y2)/2c_y = (y_1 + y_2) / 2, w=x2x1w = x_2 - x_1, and h=y2y1h = y_2 - y_1. The reverse conversion involves adding or subtracting half of the width and height from the center coordinates to recover the corner positions.

0

1

Updated 2026-05-19

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L