Mask Refine π
Turn a scratchy selection into a mask you'd actually sample with
- mask
- guide_image
- mask
- mask_inverted
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:
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.fill_holes- fill fully enclosed gaps inside the mask.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.blur- the actual gaussian feather, in pixels. 0 keeps hard edges.edge_refine- snap the edge to theguide_image. Two tiers:guided filter(fast, edge-aware filtering) andmatting(closed-form alpha matting around the edge). Both need the optional packages -opencv-contrib-pythonfor the filter,pymattingfor matting - and both need theguide_imageinput connected.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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | BHW mask; white is the selected area. | |
| expand | INT | 0-1024β1024 | Pixels to grow (+) or shrink (-) the mask. |
| blur | FLOAT | 0.00β100 | Gaussian feather strength in pixels; 0 keeps hard edges. |
| fill_holes | BOOLEAN | false | Fill fully enclosed gaps inside the mask before feathering. |
| smooth | INT | 00β256 | Melts staircase jaggies by this many pixels while keeping a hard edge; 0 is off. Runs before the feather blur. |
| black_point | FLOAT | 0.000β1 | Mask values at or below this become fully black; clears faint gray haze outside the subject. Applied last. |
| white_point | FLOAT | 1.000β1 | Mask values at or above this become fully white; solidifies the mask core. Applied last. |
| edge_refine | COMBO | off | Snap 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. |
| previewopt | BOOLEAN | true | Show this node's result on its face. Off skips writing the preview file to ComfyUI's temp folder. |
| guide_imageopt | IMAGE | RGB frames the mask belongs to; required when edge_refine is 'guided filter' or 'matting'. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | The refined BHW mask. |
| mask_inverted | MASK | The refined mask inverted, for operations that target the background. |