What is a bounding box?

A bounding box is the smallest axis-aligned rectangle that fully contains an object or the visible content of an image, defined by its left, top, right and bottom edges.

By · Updated

Want the full walkthrough? Read: How to trim transparent pixels in Photoshop →

Explained in more detail

In image work, the bounding box of the visible content is the tightest rectangle that still contains every pixel you care about. For a transparent PNG, that means every pixel whose alpha is above a threshold. Everything outside the rectangle is empty border.

Computing it is a single scan of the pixels. Walk the image and track the smallest and largest x and y positions at which a visible pixel occurs. Those four numbers, minimum x, minimum y, maximum x and maximum y, are the box. Its width is maximum x minus minimum x plus one, and likewise for height.

The bounding box is the core of trimming. Once you know it, cropping the canvas to that rectangle removes the empty margins while keeping the content pixel-for-pixel identical. Triim's trim tool does exactly this and counts a pixel as content when its alpha is above 10 out of 255.

"Axis-aligned" matters: the box always has horizontal and vertical sides, even if the content is a tilted shape. A diagonal line therefore has a bounding box much larger than the line itself. The same word is used in object detection and CSS, but the idea is identical: the smallest straight-sided rectangle around something.

A single stray, nearly invisible pixel far from the main content can stretch the box a long way. That is the reason a threshold, rather than "any alpha above zero", is usually used when computing it.

Related terms

Try it in Triim

Further reading

Part of the Triim image terms glossary, by Rocco Bombardieri.