ComfyUI Node
Mask Refine
Cleans up a mask in one fixed-order pass: expand (grow/shrink by whole pixels), fill enclosed holes (all of them, or only those up to max_hole_size), smooth (melts staircase jaggies without feathering), feather with a gaussian blur, edge-refine against the optional guide_image (guided filter or alpha matting), then remap levels with black_point / white_point to clear gray haze. Returns the refined mask and its inverse.
Mask Refine
- mask
- guide_image
- mask
- mask_inverted
◄expand0►
◄blur0.0►
◄fill_holesfalse►
◄smooth0►
◄black_point0.00►
◄white_point1.00►
◄edge_refineoff►
◄previewtrue►
◄max_hole_size0.0►
CategoryQG-tools/Mask
Inputs (11)
| 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. Gaps that touch the frame edge never count as holes. |
| 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 the refined mask on the node 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'. | |
| max_hole_sizeopt | FLOAT | 0.00–100 | The biggest hole fill_holes fills, in percent of the picture. 2 fills the gaps a quick brush leaves but keeps a person or pet you left unpainted; 0 fills every hole. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | The refined BHW mask. |
| mask_inverted | MASK | The refined mask inverted, for operations that target the background. |