MVEx Mask Cleanup
A Video Mask Vacuum That Won't Eat Your Subject's Soft Edges
- masks
- masks
Video segmentation is noisy. You run SAM or a per-frame segmentation and the mask batch comes back with specks that appear for a frame and vanish, little blobs that flicker like bad LEDs, and a subject edge that shivers. If that mask feeds a crop tracker or an inpaint mask, all that noise becomes visible junk - jitter, bleeding, speckles that get regenerated as artifacts. MVEx Mask Cleanup exists to strip the specks and flickering blobs out of a video mask batch while keeping the actual subject, soft edges and all.
How it works
Two methods, one job, both operating in 3D - space and time, because a blob that only lives for one frame is a different problem from a spec that sits there every frame.
- shrink_grow (the default): erodes the mask spatially so anything thinner than about twice the
shrinkdistance disappears, then instead of dilating back, restores the exact original shape of every blob whose core survived. The subject's silhouette - thin protrusions, antennae, loose hair - comes back untouched; only the stuff too thin to survive a shrink is gone. - components: labels connected blobs in time+space and drops the ones that are both small (
min_pixels, default 32) and short-lived (min_frames, default 2). Good when your noise is discrete blobs rather than thin fuzz.
Both then apply edge_grow (default 4): the kept regions are grown by a few pixels so the subject's soft, feathered edges - which the thresholding step would otherwise shave - survive. The output keeps the same size and the same soft mask values as the input; it just has less junk in it.
The inputs that matter
- masks - the batch, one mask per frame. It's all you strictly need.
- threshold (default 0.5) - mask values above this count as subject when finding blobs. If your masks are feathered and you keep losing the subject, this is the first dial; the tooltip's phrasing is "above this count as subject."
- method - the dropdown switches the extra inputs:
shrink/min_framesfor shrink_grow,min_pixels/min_framesfor components. - edge_grow - how many pixels the survivors get back.
Output is a single masks batch, same dimensions, one mask per frame - drop it straight into Subject Crop or Mask To Latent Space.
Where it sits in the pipeline
This is the pack's gatekeeper node, and the README's own workflow shows why: Subject Crop's "guaranteed" padding counts mask noise as subject, so noisy segmentation is the top cause of a jumpy crop. The recommended order is Mask Cleanup → Subject Crop → sample → Subject Uncrop. It also pairs well with any video inpainting where the mask comes from a model rather than a brush - inpainting masks with flickering specks produce exactly the kind of "brief flickering blobs" this node is built to remove.
Install
Part of MaskVidExperiments, so the standard install covers it. ComfyUI Manager, search "MaskVidExperiments", or:
cd ComfyUI/custom_nodes
git clone https://github.com/drozbay/MaskVidExperiments
then restart. No weights to download, no dependencies beyond ComfyUI's own, and the pack needs ComfyUI v0.15.0+.
One honest caveat: this cleans noise, it won't fix a bad segmentation. If the real subject is being split across frames or the mask is missing half the person, no cleanup method will save the crop - fix the segmentation first. And watch the edge_grow vs. threshold interaction: crank edge_grow if the subject keeps losing its feathered rim, but if you're growing so much the mask bleeds into the background, your threshold is too high and the edges are reading as background.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | Mask batch to clean, one mask per frame. | |
| threshold | FLOAT | 0.500–1 | Mask values above this count as subject when finding blobs. |
| method | COMBO | shrink_grow: shrinks the mask so thin specks vanish, then restores the surviving blobs' exact shapes. components: drops blobs that are both small and short-lived. | |
| edge_grow | INT | 4 | Grow kept regions by this many pixels so the subject's soft edges are preserved. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| masks | MASK | Cleaned masks, same size and soft values as the input. |