to_array#

rlemasklib.RLEMask.to_array(fg_value=1, bg_value=0, dtype=np.uint8, order='F', *, value=_UNSET)[source]#

Convert the RLE mask to a dense numpy array.

Background pixels get bg_value and foreground pixels get fg_value.

If either fg_value or bg_value is a tuple, list, or 1D array, the result is a 3D HWC array with one channel per element. A scalar value for the other parameter is broadcast to all channels.

The RLE is internally stored for the Fortran order, so order=’F’ is faster, because ‘C’ requires a transpose. To improve efficiency, the transpose is done either in RLE or in dense form, depending on the sparseness of the mask.

Parameters:
  • fg_value – the foreground value (scalar for 2D, tuple/list/array for HWC)

  • bg_value – the background value (scalar for 2D, tuple/list/array for HWC)

  • dtype – the numpy dtype of the resulting array (default: np.uint8)

  • order – the order of the array (‘C’ for row-major, ‘F’ for column-major)

  • value – deprecated alias for fg_value

Returns:

A 2D or 3D numpy array representing the mask.

Return type:

ndarray