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 >=
thresholdbecome foreground (1), others background (0), comparing in the array’s own dtype. The default threshold is 1, so for integer input any nonzero value is foreground; note this means a float probability map is thresholded at 1 by default (e.g. 0.5 becomes background) – passthreshold=0.5for such inputs.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. Values >=
threshold(compared in the array’s own dtype) are foreground, others background.threshold (float) – pixel value threshold for binarization. Values >= threshold become foreground. Default is 1 (any nonzero value for unsigned input). For uint8 and bool input the threshold must be in [1, 255]; an out-of-range threshold would only produce a constant mask, so it is rejected as a likely caller bug.
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: