from_label_map_png#

static rlemasklib.RLEMask.from_label_map_png(path=None, data=None)[source]#

Convert a PNG label map directly to a dict of RLEMasks.

Decodes PNG and builds RLEs in a single pass, avoiding intermediate numpy array allocation.

Label 0 is treated as background and not included in the output. Labels 1-255 become individual RLEMasks.

Parameters:
Returns:

A dict mapping label values (1-255) to RLEMask objects. Only labels that appear in the input are included.

Raises:

ValueError – If neither path nor data is provided, or both are provided.

Return type:

dict[int, RLEMask]