bounds2slices¶

bounds2slices(bounds, stride=1)[source]¶

Convert bounds to slices.

Create a tuple of slices for each start/stop pair in bounds.

Parameters:
  • bounds (tuple(int)) – Iterable of integer bounds. Must be even in length with the first half as starting values and the second half as end values, e.g. (start_x, start_y, stop_x, stop_y).

  • stride (int) – Stride to apply when converting to slices.

Returns:

Tuple of slices in image read order (y, x, channels).

Return type:

tuple of slice

Example

>>> from tiatoolbox.utils.transforms import bounds2slices
>>> import numpy as np
>>> bounds = (5, 5, 10, 10)
>>> array = np.ones((10, 10, 3))
>>> slices = bounds2slices(bounds)
>>> region = array[slices, ...]