MaskContourFill_YC
Fill in a line-art or outline mask so it becomes a solid region
- mask
- filled_mask
Some masks arrive as outlines rather than filled shapes - from edge detectors, from hand-drawn strokes that only traced a border, from segmentation that left thin rings. An edit model wants a solid region, not a line. MaskContourFill_YC finds every contour in your mask and fills it, so the scribble becomes a filled blob you can actually inpaint or condition on.
The same pass doubles as a speckle filter. Every contour below min_area (default 50, range 0–10000) gets dropped, so dust, noise flecks, and accidental dots in your mask vanish while the real regions stay. That's often the more useful half of the node - it's a cheap "clean my mask" step that removes the garbage without touching the blobs you care about.
How it works
Straight OpenCV: it binarizes the mask, runs cv2.findContours in RETR_LIST mode, keeps contours whose contourArea clears min_area, and draws each survivor filled (drawContours with thickness -1) onto a blank canvas. The output is a hard-edged mask - no feathering, no anti-aliasing. If you want soft edges after, blur or feather downstream.
Note it processes a single mask: if you feed a batch, it takes the first frame and ignores the rest. Feed it one mask at a time, or loop per frame.
The inputs
Just two: mask and min_area. Default 50 works well for most cases; if your mask is high-res and the blobs are large, you can push it up and watch small artifacts disappear. min_area is in raw pixels, not a fraction of the image, so it means different things at different resolutions - keep that in mind when you reuse a setting across image sizes.
Output
One MASK, filled_mask, same size as the input. Wire it into anything that consumes masks: inpaint conditioning, a preview, an image composite mask input.
Install
From the ComfyUI-YCNodes pack. ComfyUI Manager → search "ComfyUI-YCNodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Restart ComfyUI. Deps are the usual torch, numpy, pillow, opencv-python, scipy - no downloads, no models. It appears under "YCNode/Mask".
Gotchas
The RETR_LIST mode means nested contours are treated independently - a donut (outer ring + inner hole) gets both filled, producing a solid disk with the hole filled in too. That's usually what you want when cleaning up masks, but if you genuinely need to preserve holes, this isn't the node. And remember the single-frame behavior: batch in, only the first frame comes out. For a version that respects nested structure and outputs per-component, the same pack's Mask Split Filter is the sibling to look at.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| min_area | INT | 500–10000 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| filled_mask | MASK | — |