find_padding¶

find_padding(read_location, read_size, image_size)[source]¶

Find the correct padding to add when reading a region of an image.

Parameters:
  • read_location (tuple(int)) – The location of the region to read.

  • read_size (tuple(int)) – The size of the location to read.

  • image_size (tuple(int)) – The size of the image to read from.

Returns:

Tuple of padding to apply in the format expect by np.pad. i.e. ((before_x, after_x), (before_y, after_y)).

Return type:

np.ndarray

Examples

>>> from tiatoolbox.utils.image import find_padding
>>> location, size = (-2, -2), (10, 10)
>>> # Find padding needed to make the output (10, 10)
>>> # if the image is only (5 , 5) and read at
>>> # location (-2, -2).
>>> find_padding(location, size, image_size=(5, 5))