Nodes/AusBoss/Mask Refine πŸ†Ž
ComfyUI Node

Mask Refine πŸ†Ž

Turn a scratchy selection into a mask you'd actually sample with

By ausbossΒ·Created 2 months agoΒ·Updated 3 days agoΒ· 2
Mask Refine πŸ†Ž
  • mask
  • guide_image
  • mask
  • mask_inverted
β—„expand0β–Ί
β—„blur0.0β–Ί
β—„fill_holesfalseβ–Ί
β—„smooth0β–Ί
β—„black_point0.00β–Ί
β—„white_point1.00β–Ί
β—„edge_refineoffβ–Ί
β—„previewtrueβ–Ί

Rough masks are the norm in ComfyUI - a quick paint, a segmenter's output, an edge pass - and feeding one straight into a sampler is how you get a seam. Mask Refine πŸ†Ž is the AusBoss pack's cleanup pass: one node that grows, smooths, feathers, and levels a mask in a fixed order, and returns both the refined mask and its inverse so you can target the background too.

The pipeline, in order

The node runs a fixed sequence, and knowing the order is half the battle:

  1. expand - grow (positive) or shrink (negative) by whole pixels. Range is βˆ’1024 to 1024, so this also handles the "the segmenter under-covers the subject" problem.
  2. fill_holes - fill fully enclosed gaps inside the mask.
  3. smooth - melts staircase jaggies while keeping a hard edge. This is the distinctive one: it's not a feather. Feathering softens the whole edge; smoothing cleans the jaggedness without making the edge mushy.
  4. blur - the actual gaussian feather, in pixels. 0 keeps hard edges.
  5. edge_refine - snap the edge to the guide_image. Two tiers: guided filter (fast, edge-aware filtering) and matting (closed-form alpha matting around the edge). Both need the optional packages - opencv-contrib-python for the filter, pymatting for matting - and both need the guide_image input connected.
  6. black_point / white_point - remap levels, applied last. Values at or below black_point become fully black (clears the gray haze outside a subject); values at or above white_point become fully white (solidifies the mask core).

What you actually set

The panel previews the refined mask itself, which is the feature that saves the most time - you can see what a setting did instead of sampling to find out. It opens on expand and blur alone, with the rest behind MORE, and there's an AUTO button that sets both from the mask's size. That's genuinely well-thought-out: a feather is a fraction of the picture, so the blur that covers a watermark rim at 576px is a smear on a thumbnail. AUTO scales the values to the mask.

Outputs are mask (the refined result) and mask_inverted (for background-targeting operations).

Install

cd ComfyUI/custom_nodes
git clone https://github.com/ausboss/ComfyUI-AusBoss.git

Restart ComfyUI and search for AusBoss (Manager: ComfyUI-AusBoss). The core mask ops need nothing extra; only the edge-refine tiers add dependencies:

cd ComfyUI/custom_nodes/ComfyUI-AusBoss
pip install opencv-contrib-python   # guided filter
pip install pymatting               # matting

Minimum ComfyUI 0.27.1.

Troubleshooting

If an edge_refine mode errors, it's naming the package you need to install - the pack deliberately fails loudly there rather than silently producing a different mask, because you asked for that mode by name. If the mask comes out hard-edged when you expected soft, blur is your feather - smooth explicitly does not feather. And if gray haze survives around the subject, that's what black_point is for; raise it until the haze clears but the subject core stays solid.

CategoryπŸ†Ž AusBoss/Mask

Inputs (10)

NameTypeDefaultDescription
maskMASKBHW mask; white is the selected area.
expandINT0-1024–1024Pixels to grow (+) or shrink (-) the mask.
blurFLOAT0.00–100Gaussian feather strength in pixels; 0 keeps hard edges.
fill_holesBOOLEANfalseFill fully enclosed gaps inside the mask before feathering.
smoothINT00–256Melts staircase jaggies by this many pixels while keeping a hard edge; 0 is off. Runs before the feather blur.
black_pointFLOAT0.000–1Mask values at or below this become fully black; clears faint gray haze outside the subject. Applied last.
white_pointFLOAT1.000–1Mask values at or above this become fully white; solidifies the mask core. Applied last.
edge_refineCOMBOoffSnap the mask edge to the guide_image. 'guided filter' is fast edge-aware filtering (needs opencv-contrib-python); 'matting' solves closed-form alpha matting around the edge (needs pymatting). Both require the guide_image input.
previewoptBOOLEANtrueShow this node's result on its face. Off skips writing the preview file to ComfyUI's temp folder.
guide_imageoptIMAGERGB frames the mask belongs to; required when edge_refine is 'guided filter' or 'matting'.

Outputs (2)

NameTypeDescription
maskMASKThe refined BHW mask.
mask_invertedMASKThe refined mask inverted, for operations that target the background.