from_array#

static rlemasklib.RLEMask.from_array(mask_array, threshold=1, is_sparse=True, thresh128=False)[source]#

Create an RLEMask object from a dense mask.

Pixels with values >= threshold become foreground (1), others background (0). Default threshold is 1, so any nonzero pixel is foreground.

If mask_array is C contiguous, a transpose has to take place since the internal RLE format encodes the mask in Fortran order. If is_sparse is set to True, the transpose, if necessary, will be performed in RLE format, otherwise it will be performed in dense array format.

Parameters:
  • mask_array (ndarray) – a numpy array of numerical type where nonzero means foreground and zero means background.

  • threshold (int) – pixel value threshold for binarization. Values >= threshold become foreground. Default is 1 (any nonzero). Common values: 1, 128.

  • is_sparse (bool) – hint that it is more efficient to transpose the mask in RLE form, only affects efficiency when the mask is C contiguous.

  • thresh128 (bool) – deprecated, equivalent to threshold=128.

Return type:

RLEMask