Nodes/Enigmatic Nodes/Mask Remove Small Regions
ComfyUI Node

Mask Remove Small Regions

Kill the noise dots that wreck your crops

By enigmatice·Created 2 months ago·Updated 7 days ago· 1
Mask Remove Small Regions
  • mask
  • mask
min_area500
threshold0.50

Look at a raw mask from a detection or matting node and you'll see it: one clean blob for the subject, plus a constellation of tiny white specks - a stray reflection, a mis-segmented bit of background, a hair here, a glint there. Usually those specks are harmless. Then you feed the mask to a crop node and the crop jumps to wherever the noise is biggest, because crop nodes find their bounding box from everything white in the mask. Mask Remove Small Regions erases every disconnected blob smaller than min_area pixels, so only the regions you actually care about survive.

It ships in Enigmatic Nodes, a small utility pack by the individual dev enigmatice. Pure local Python, no models, no downloads. It's the spatial cleanup half of the pack's mask-hygiene story - its sibling Mask Hold Until Stable handles the temporal half (jitter over time), this one handles the spatial half (junk in a single frame).

How it works

The mechanism is textbook connected-component analysis, done with scipy.ndimage.label: the mask is binarized at threshold, each disconnected white region is labeled, and any region whose pixel count is below min_area is dropped. Regions that survive keep their original mask values - so soft, feathered edges aren't flattened to hard binary; only the specks disappear. That's a nicer behavior than a blind threshold-and-clear, and it's why the output still composites cleanly.

It processes every frame in the batch independently, which is exactly what you want for a per-frame detection stream. It's also fast - this is pure numpy/scipy math on tensors, no VRAM-heavy model in the loop.

The inputs that matter

  • mask - the mask (or batch of masks) to clean.
  • min_area (default 500) - the minimum pixel count for a region to survive. This is the dial you'll actually tune. Remember it's in pixels, so a 1024px mask and a 512px mask need different numbers; if specks survive, raise it, and if you're losing real regions, lower it.
  • threshold (default 0.5) - what counts as "white" when binarizing. Values below it are ignored entirely. You rarely need to touch this; 0.5 is the right default for masks that come out of most nodes.

The output

A single mask - the same shape and frame count, with small blobs removed and surviving regions untouched.

Where it wires in

The canonical use is upstream of a crop: clean the mask first, then crop, and the crop box stops latching onto noise. It's also handy before any mask-based inpainting or compositing where specks would create artifacts - an inpaint sampler will happily regenerate the area under a stray speck if you let it through. In the pack's own framing, it exists precisely so crop nodes "don't jump to unexpected positions."

Installing it

Same for every node in the pack:

  • ComfyUI Manager - search Enigmatic Nodes, install, restart.
  • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/enigmatice/comfyui-enigmatic-nodes, then restart.

No model files to fetch. The pack declares scipy, opencv-python, numpy, Pillow, and torch; ComfyUI core already ships all but opencv-python (which you almost certainly have from another pack), and Manager installs deps for you.

Common issues

  • Specks still survive. min_area is in pixels and the default 500 assumes a fairly low-res mask. At 1K resolution, specks are routinely bigger than 500 pixels - raise it.
  • Real regions disappear. You've pushed min_area too high, or threshold is set so feathered edges binarize away. Back the threshold down toward 0.5.
  • Nothing changes at all. If all your blobs are already bigger than min_area, there's nothing to remove - that's a success, not a bug.

It's a young node from a pack with no community footprint yet, so don't expect a tutorial ecosystem. But it's a genuinely useful five-minute install: drop it in front of a crop, tune one number, and watch the jumpy bounding box calm down.

Categoryenigmatic

Inputs (3)

NameTypeDefaultDescription
maskMASK
min_areaINT5001–500000
thresholdFLOAT0.500.01–1

Outputs (1)

NameTypeDescription
maskMASK