Nodes/ComfyUI Essentials/πŸ”§ Mask Fix
ComfyUI Node Runs on cloud

πŸ”§ Mask Fix

Mask Fix β€” clean up ugly masks before they wreck your inpaint

By cubiqΒ·Created 3 years agoΒ·Updated about a year agoΒ· 1,152
πŸ”§ Mask Fix
  • mask
  • MASK
β—„erode_dilate0β–Ί
β—„fill_holes0β–Ί
β—„remove_isolated_pixels0β–Ί
β—„smooth0β–Ί
β—„blur0β–Ί

Masks are almost never clean. You run a segmentation model or a CLIPSeg pass and what comes back is jagged at the edges, full of little pinholes, speckled with stray pixels off in the corner. Feed that straight into an inpaint or a composite and you get hard seams, missed spots, and floating garbage. Mask Fix is the cleanup station you run the mask through before it does any real work.

Think of it as one node that bundles the five mask-tidying operations you'd otherwise chain together, all in the order you'd actually want them.

What it does

You give it a MASK, and it hands back a cleaned MASK. In between, five knobs, each doing one job:

  • erode_dilate - grows or shrinks the whole mask. Negative values erode (pull the edge inward), positive values dilate (push it out). This is the one you'll touch most. Dilate a few pixels to give an inpaint some breathing room around the subject; erode to tighten a mask that's grabbing background.
  • fill_holes - closes interior gaps. If your mask of a person has a hole where their shirt logo confused the segmenter, this fills it in.
  • remove_isolated_pixels - deletes tiny disconnected specks. That one stray blob of mask 200 pixels away from your actual subject? Gone.
  • smooth - rounds off jagged, staircased edges so the boundary follows a cleaner curve.
  • blur - softens the mask edge into a gradient. This is what kills hard composite seams; a few pixels of blur turns a cut-out look into a blend.

Every value defaults to 0, meaning a fresh node does nothing until you dial something in. That's the right default - you add exactly the corrections your mask needs and leave the rest alone.

The order matters, and that's the point

The reason to use one Mask Fix instead of five separate nodes is that cubiq baked in a sensible sequence: clean up the shape (erode/dilate, fill, despeckle), then soften it (smooth, blur). If you tried to hand-wire these, getting the order wrong - blurring before you despeckle, say - gives you mush. Mask Fix handles that so you don't think about it.

Typical recipe

For a subject you're about to inpaint or composite: a small dilate (2–8) to avoid a tight halo, fill_holes if the interior is patchy, a touch of remove_isolated_pixels to kill specks, and a modest blur (4–12) for a soft edge. Start conservative - over-blurring a mask bleeds your edit into areas you wanted untouched.

Installing it

Mask Fix is part of ComfyUI Essentials by cubiq (Matteo Spinelli, the developer behind ComfyUI_IPAdapter_plus):

  • ComfyUI Manager: search "ComfyUI Essentials" β†’ Install β†’ restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/cubiq/ComfyUI_essentials, install requirements.txt, restart.

You'll recognise it by the πŸ”§ wrench and the + on the class name (MaskFix+).

Gotchas

The classic mistake is cranking blur to fix a bad mask when the real problem is the shape. Blur softens edges; it doesn't add the region a segmenter missed. If your mask is wrong, fix the shape first (dilate, fill) and use blur only for the finishing feather.

Watch the edges of the frame - a big dilate can push the mask past the image border, which sometimes leaves a hard line right at the edge.

Pack-level note: cubiq set Essentials to maintenance-only in April 2025. It still works well and Mask Fix is heavily used, but if it breaks right after a major ComfyUI update, roll ComfyUI back or patch the file yourself - no fixes are coming from upstream. If the node shows up red as "missing," the pack failed to load; check your startup log and reinstall through Manager.

Categoryessentials/mask

Inputs (6)

NameTypeDefaultDescription
maskMASKβ€”
erode_dilateINT0-256–256β€”
fill_holesINT00–128β€”
remove_isolated_pixelsINT00–32β€”
smoothINT00–256β€”
blurINT00–256β€”

Outputs (1)

NameTypeDescription
MASKMASKβ€”