Nodes/Lostless Nodes/Lostless Image To Mask
ComfyUI Node

Lostless Image To Mask

Turn any black-and-white image into a real ComfyUI mask

By lostlessvisuals·Created 7 months ago·Updated 10 days ago· 0
Lostless Image To Mask
  • images
  • masks
  • mask_image
conversion_modePreserve Grayscale
threshold0.50
invertfalse

ComfyUI's mask convention is simple and constantly trips people up: a mask is a grayscale tensor where white is the affected region. But half the time what you actually have is a black-and-white PNG - something you drew in a paint app, a segmentation output, an alpha channel - and getting that into a MASK tensor that an inpaint or video node will accept is where the chain of tiny converter nodes and manual saves begins. Lostless Image To Mask does the whole conversion in one node, works on entire batches, and gives you a preview image so you can see what the model is about to receive.

The WANVace prefix in the class name hints at its lineage - it ships from the pack's embedded mask-editor package, the same corner of the ecosystem as Wan's VACE mask-based video editing. But don't overthink the branding: the node itself is a plain, dependency-free converter. No model, no weights, nothing to download.

How it works

You feed it an IMAGE tensor. It cleans the values (NaNs to zero, clamps to 0–1), then reduces RGB to luminance using the standard BT.709 weights (0.2126 R, 0.7152 G, 0.0722 B). Then it hands you two conversion modes:

  • Preserve Grayscale - the gray value is the mask. A soft gradient stays a soft mask, which is what you want for partial-strength or feathered regions.
  • Threshold - hard binary: anything at or above threshold becomes 1, everything below becomes 0. That's your crisp, paint-bucket-style mask.

The invert toggle flips the result (1 - mask), which is the fix for the single most common mistake: your white paint coming through as the unaffected area because the source convention was reversed.

The inputs that matter

  • images - the IMAGE batch. Works across frames, so video frames and image sequences convert in one pass.
  • conversion_mode - Preserve Grayscale (default) or Threshold.
  • threshold - FLOAT, 0–1, default 0.5. Only matters in Threshold mode.
  • invert - BOOLEAN, default off. Flip when your mask is backwards.

The outputs

  • masks - a MASK tensor, ready for any mask-consuming input: inpainting/outpainting conditioning, the pack's own mask editor, a detailer loop, or Wan VACE-style mask-to-video.
  • mask_image - the same mask expanded back to a 3-channel IMAGE for preview. Wire it into a Preview Image node and you can eyeball exactly what the model sees, threshold clipping included.

Where it fits

This is a bridge node, and it slots in right at the start of a mask pipeline. Draw a mask in any editor, load it, convert it here, and feed the result into your inpaint or VACE workflow. Because it preserves grayscale by default, it plays nicely with soft masks - but for most practical masking you'll end up in Threshold mode with threshold at 0.5, and that's fine. The preview output is the part people underestimate: mask bugs are invisible until you composite, and this node hands you the check for free.

Install

From ComfyUI Manager, search Lostless Nodes. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/lostlessvisuals/comfyui-lostless-nodes
python -m pip install -r ComfyUI/custom_nodes/comfyui-lostless-nodes/requirements.txt

Restart ComfyUI afterward. The pack's requirements (opencv-python, numpy, PyQt5, psutil) are shared with the mask editor; none of it is needed for the conversion itself, but you install the pack as one unit regardless.

Gotchas

  • White = affected. If your inpaint results are inverted, hit invert rather than re-drawing.
  • Threshold makes hard edges. If your mask looks jagged in the preview, drop back to Preserve Grayscale and let the model soften it - or keep the hard mask and blur downstream.
  • It converts, it doesn't detect. If you want a mask found for you (a face, a background), this isn't that node - pair a detector or promptable segmenter before it instead.
Categorylostless/mask

Inputs (4)

NameTypeDefaultDescription
imagesIMAGE
conversion_modeCOMBOPreserve Grayscale2 options: Preserve Grayscale, Threshold
thresholdFLOAT0.500–1
invertBOOLEANfalse

Outputs (2)

NameTypeDescription
masksMASK
mask_imageIMAGE