__getitem__#

rlemasklib.RLEMask.__getitem__(key)[source]#

Crop the RLE mask to get a submask, by slicing, or retrieve a single pixel value.

Parameters:

key (Union[slice, tuple[slice, slice], tuple[int, int]]) – a slice, a tuple of two slices or two ints (one for height and one for width)

Returns:

A new RLEMask object representing the submask.

Raises:

ValueError – if the key is not a tuple of two slices or two integers.

Return type:

Union[int, RLEMask]

Examples

With slices:

>>> rle = RLEMask(np.eye(4))
>>> rle[1:3, 2:4].shape
(2, 2)

With integers:

>>> rle = RLEMask(np.eye(4))
>>> rle[1, 1]
1