Remove Small Soft Mask Regions
Kill the mask speckles without flattening your soft edges
- mask
- mask
If you've ever piped a SAM3 mask or a text-prompt mask into a detailer and watched the result dance around ten tiny specks you never intended, this is the node you were missing. Remove Small Soft Mask Regions is a cleanup pass for masks: it drops small connected regions that are almost certainly noise, and - this is the part that matters - it does it without flattening the soft mask values of everything it keeps.
A quick bit of context on why that distinction matters. This pack's SAM3 Prompt To Mask deliberately outputs a non-binarized "soft" mask so downstream nodes can do their own thresholding and feathering. Hard binary masks are fine for "replace everything inside this shape," but soft values are what make inpaint edges blend instead of slicing. The danger with naive cleanup - binarize, then drop small blobs - is that you lose that gradation along the edges you actually want to keep. This node keeps it: it thresholds only to judge which regions are big enough to be real, then preserves the original soft values of the surviving pixels.
How it works
Under the hood it's a three-step recipe, and knowing it saves you from setting the knobs wrong:
- Pixels above
threshold(default 0.1) are treated as foreground. This is only for measuring - nothing here is permanently binarized. - The foreground is split into 8-connected regions.
- Any region whose area is smaller than
min_image_area_percentof the total image is removed. Everything else passes through with its original soft values intact.
Set min_image_area_percent to 0 and the node just passes the mask through unchanged - handy for turning the filter on and off per workflow.
The inputs that matter
Only three, and you'll mostly touch two of them:
- mask - the soft or binary input, as a
MASKtensor. - min_image_area_percent (default 0.004) - this is a percentage of the image area, not a fraction. On a 1024×1024 image, 0.004% is roughly 42 pixels, which is perfect for killing SAM3's stray flecks. If you're trying to drop genuinely small objects (say a whole distant person), crank this into whole-percent territory - 1.0 drops anything under ~1% of the frame.
- threshold (default 0.1) - the "what counts as foreground" cutoff. If your mask has faint, tentative values you care about, drop this so they count.
The single output, mask, is the cleaned soft mask. Wire it into the pack's Detailer Start, a mask-to-image inpaint setup, or Mask Overlay Comparer to eyeball the result before committing to a full run.
Install
It ships in the ComfyUI-Info-Prompt-Toolkit pack. Easiest path is ComfyUI Manager - search the pack title and hit install - or do it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/kinorax/comfyui-info-prompt-toolkit.git
cd comfyui-info-prompt-toolkit
pip install -r requirements.txt
Then restart ComfyUI. This particular node needs nothing extra beyond the base install - no model downloads, no heavy dependencies. The one gotcha to remember: because it sits in a pack that also ships SAM3 and tagger nodes, the shared requirements.txt pulls in a few extras (timm, ftfy, regex, iopath, typing_extensions, cryptography) even if you only ever use mask cleanup. They install quietly and you can forget about them.
Where people get burned
The classic mistake is reading min_image_area_percent as a decimal fraction and setting 0.004 when they meant "remove everything tiny," then wondering why nothing changed. If you want aggressive cleanup, go several orders of magnitude higher. And remember the threshold: it's 0.1 by default, so a mask that's all soft 0.05–0.08 values looks empty to this node. When in doubt, lower the threshold, not the area.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | Soft or binary input mask. Regions are judged from thresholded foreground while kept pixels preserve their original soft values. | |
| min_image_area_percent | FLOAT | 0.0040–100 | Thresholded connected regions smaller than this image-area percentage are removed. |
| threshold | FLOAT | 0.100–1 | Pixels above this value define foreground regions before filtering. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |