MaskToRle
Shrink a mask down to COCO RLE for your API response
- mask
- masks_rle
A mask as a PNG is a lot of bytes for what's fundamentally a yes/no grid. RLE - run-length encoding, the format the COCO dataset (and the pycocotools library) standardized for exactly this - stores it instead as "N pixels off, then M pixels on, then...", which for anything but pure noise is dramatically smaller than a bitmap. MaskToRle does that conversion, and it's the format this pack's own SAM auto-segmentation nodes lean on to hand back dozens of detected regions without dozens of separate PNGs.
The one thing to know before you use it
The pack's own README is upfront about the tradeoff: RLE here is binary-only. It stores which pixels are in or out, full stop - there's no room for a soft, antialiased edge the way a feathered or blurred mask has one. Round-trip a feathered mask through RLE and back and you won't get the softness back; that information is gone the moment it's encoded. If you need the original mask, keep it around separately rather than relying on RLE to preserve it.
The inputs and outputs that matter
mask(MASK) - the mask to encode.output_mode(enum:uncompressed_rledefault, orcoco_rle) - which flavor.coco_rleis the more compact,pycocotools-compatible variant.masks_rle(MASK_RLE) - the encoded output.
Note that MASK_RLE is a type specific to this pack - nothing outside comfyui-easyapi-nodes speaks it directly. Treat it as an internal shuttle format: decode it with this pack's RleToMask if you need a real mask back inside the graph, or serialize it out as compact JSON in an API response if the point was transport rather than further processing in ComfyUI.
How to install it
Via ComfyUI Manager: search comfyui-easyapi-nodes, install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
cd comfyui-easyapi-nodes
pip install -r requirements.txt
Restart ComfyUI. No models needed for this node itself.
Common issues & troubleshooting
The binary-only lossiness above is the main gotcha - it's not a bug if a feathered mask comes back hard-edged after a round trip, that's what the format does by design.
Mode mismatch is the other one. Encode as coco_rle and decode expecting uncompressed_rle (or the reverse) and you'll get garbage rather than a clear error. Keep output_mode here and rle_mode on RleToMask set to the same value for any given payload.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| output_mode | COMBO | uncompressed_rle | 2 options: uncompressed_rle, coco_rle |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| masks_rle | MASK_RLE | — |