Nodes/MachinePainting Nodes/πŸ‘Ύ Mask Editor
ComfyUI Node

πŸ‘Ύ Mask Editor

Polish any mask without leaving the graph β€” grow, shrink, blur, fill

By machinepaintingΒ·Created 10 months agoΒ·Updated 4 months agoΒ· 9
πŸ‘Ύ Mask Editor
  • mask
  • mask
  • mask_preview
β—„grow_shrink0β–Ί
β—„blur_radius0.0β–Ί
β—„fill_holesfalseβ–Ί
β—„hole_size_threshold500β–Ί
β—„invertfalseβ–Ί
β—„threshold0.50β–Ί
β—„apply_thresholdfalseβ–Ί

You know the situation. A segmentation node or an inpaint mask gives you something almost right - the edges are a pixel too loose, there's a stray speck of background inside the subject, and the boundary is so soft it'll feather weirdly when you composite. You don't want to regenerate the mask, you want to fix it. That's exactly what πŸ‘Ύ Mask Editor from the MachinePainting Nodes pack does: it's the mask equivalent of a quick Photoshop refine pass, minus the trip out of ComfyUI.

What it actually does

Mask Editor takes one mask and applies up to four clean-up operations in a single pass:

  • grow_shrink (-100 to 100) - expands or contracts the mask. Positive grows it out past the object edges, negative trims it in. This is your fix for masks that clip the subject or bleed over the background.
  • blur_radius (0 to 50) - softens the mask edge. Handy before inpainting, where a hard edge makes the model treat the boundary like a sharp line and you get visible seams.
  • fill_holes with hole_size_threshold (100–10000, default 500) - patches interior holes left behind by a model that missed a patch inside the subject. Threshold is roughly "holes smaller than this many pixels get filled."
  • invert and threshold - flip the mask, or snap soft grayscale edges to a hard cut. apply_threshold gates that: turn it on and threshold (0–1) decides what counts as foreground.

The only required input is mask (MASK). Everything else is optional and defaults to "leave it alone," so you can chain two Mask Editors - blur here, grow there - without fighting.

Outputs are mask (the cleaned MASK, wire it into your KSampler via a mask-conditioning node or into compositing) and mask_preview (an IMAGE). The preview output is the sleeper feature: you get an in-node look at the result without adding a preview node, which is the difference between "looks fine" and actually checking edges.

The workflow context

This slot in the graph is usually filled by Impact Pack's mask tools or ComfyUI core's GrowMask/FeatherMask. Mask Editor is the simpler, one-stop version from a pack that treats it as the shared cleanup step for its Remove Background Pro and channel masks. It matters most right before inpainting - the KB's inpainting essay is blunt that masks still own bit-identical unmasked pixels and exact placement, and that only works if the mask itself is clean. Feed it a sloppy mask and your inpaint boundary will be sloppy too.

Installing it

MachinePainting Nodes is one pack with 40 nodes, and Mask Editor rides along with it. Easiest path:

  • ComfyUI Manager β†’ Install Custom Nodes β†’ search "MachinePaintingNodes".
  • Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/machinepainting/ComfyUI-MachinePaintingNodes.git

Then restart ComfyUI. The pack's requirements.txt pulls in opencv-python-headless, numpy<3, and rembg. The rembg dependency only matters for the pack's background-removal nodes - Mask Editor itself is pure OpenCV math, so don't panic if the first run still fetches things.

Where people get burned

  • Soft masks from segmentation nodes usually want a blur + threshold combo, not just grow/shrink. Shrinking a blurry mask just trims the fuzzy zone; thresholding crisps the whole thing at once.
  • fill_holes threshold semantics: it's a pixel-count cut-off, not a ratio. For a 4K mask you may need to raise it well past 500; for small crops 500 can over-fill. Adjust per image size.
  • Negative grow_shrink on hair masks eats the flyaway strands you were trying to keep - that's a mask-quality problem no post-processing fixes. Better to re-cut with a stronger model than erode the detail away.

One honest take: for a single utility node this won't replace Impact Pack if you live in complex mask pipelines, but for "cut, refine, composite" it's the tidy middle step, and the built-in preview alone is worth the install.

CategoryMachinePaintingNodes/Mask

Inputs (8)

NameTypeDefaultDescription
maskMASKβ€”
grow_shrinkoptINT0-100–100β€”
blur_radiusoptFLOAT0.00–50β€”
fill_holesoptBOOLEANfalseβ€”
hole_size_thresholdoptINT500100–10000β€”
invertoptBOOLEANfalseβ€”
thresholdoptFLOAT0.500–1β€”
apply_thresholdoptBOOLEANfalseβ€”

Outputs (2)

NameTypeDescription
maskMASKβ€”
mask_previewIMAGEβ€”