decode_into#

rlemasklib.RLEMask.decode_into(arr, fg_value=None, bg_value=None, *, value=_UNSET)[source]#

Decode the RLE mask into an existing array.

Writes fg_value to foreground pixels and/or bg_value to background pixels. Pixels whose corresponding parameter is None are left unchanged.

Supports uint8, float32, and float64 arrays (2D or 3D HWC).

Parameters:
  • arr (ndarray) – A numpy array with shape matching the mask. Must be either C-contiguous or Fortran-contiguous (or strided for 2D uint8).

  • fg_value – The value to assign to foreground pixels (default: None, meaning unchanged).

  • bg_value – The value to assign to background pixels (default: None, meaning unchanged).

  • value – deprecated alias for fg_value

Raises:

ValueError – If array shape doesn’t match mask shape or array is not contiguous.

Return type:

None

Example

>>> canvas = np.zeros((100, 100), dtype=np.uint8)
>>> mask1.decode_into(canvas, fg_value=1)
>>> mask2.decode_into(canvas, fg_value=2)
>>> mask3.decode_into(canvas, fg_value=3)
# canvas now contains 1, 2, 3 for respective mask regions

See also

to_array()