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) or (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 set of two arrays containing integer for location and size:

  • location array
    • x location

    • y location

  • size array
    • width

    • height

Return type:

np.ndarray

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))