bounds2locsize

bounds2locsize(bounds, origin='upper')[source]

Calculate the size of a tuple of bounds.

Bounds are expected to be in the (left, top, right, bottom) / (start_x, start_y, end_x, end_y) format.

Parameters
  • bounds (tuple(int)) – A 4-tuple or length 4 array of bounds values in (left, top, right, bottom) format.

  • origin (str) – Upper (Top-left) or lower (bottom-left) origin. Defaults to upper.

Returns

A 2-tuple containing integer 2-tuples for location and size.
  • tuple - location tuple - int - x - int - y

  • size - size tuple - int - width - int - height

Return type

tuple

Examples

>>> from tiatoolbox.utils.transforms import bounds2locsize
>>> bounds = (0, 0, 10, 10)
>>> location, size = bounds2locsize(bounds)
>>> from tiatoolbox.utils.transforms import bounds2locsize
>>> _, size = bounds2locsize((12, 4, 24, 16))