Nodes/ComfyUI Temporal Mask Tools/Temporal Mask Remove Short Objects
ComfyUI Node

Temporal Mask Remove Short Objects

Killing the specks and the blinks in mask sequences

By nomadoor·Created 11 months ago·Updated 11 months ago· 2
Temporal Mask Remove Short Objects
  • mask_batch
  • Mask Batch
min_duration2
min_area_pixels10

So you unioned your per-frame detections and the strobe is gone. But the detector still leaves junk behind: a one-frame blink where the subject vanishes, or a tiny speck of segmentation ghost that persists across every single frame. Temporal Mask Remove Short Objects is the cleanup pass that gets rid of both - it's the second half of this pack's one-two punch, meant to run right after Temporal Mask Union.

The mechanism is two independent filters, applied in order, and it's worth knowing which is which because you tune them separately:

  • Spatial (area): each frame is run through OpenCV connected-component analysis (8-connectivity). Any blob with fewer than min_area_pixels active pixels is dropped. This is what kills the speck that never goes away.
  • Temporal (duration): for every pixel, the node counts how many consecutive frames it stays active, then keeps it only if that run is at least min_duration frames long. This is what kills the one-frame blink - the big blob that's there in frame 12 and gone by 13.

So the two failure modes each have their own dedicated weapon: tiny-but-persistent goes down to the area filter, big-but-brief goes down to the duration filter. The output is a MASK in the same shape and dtype you fed in - feed it (frames, H, W), (batch, frames, H, W), or a single (H, W) and it returns the same, preserving bool or float input.

Only two knobs matter, both INTs: min_duration (default 2) and min_area_pixels (default 10). The defaults are genuinely sensible starting points - set min_duration = 1 or min_area_pixels = 0 to disable one of the two filters entirely, which is a legitimate way to use the node as a pure area or pure duration cleaner. If your detector emits specks at high resolution, raise min_area_pixels before touching anything else; a 10-pixel threshold is nearly nothing at 1080p.

Honest caveats, because this node has two real ones. First, the area filter runs through numpy/OpenCV on CPU - the opencv-python in the pack's requirements is the one genuine dependency, and if ComfyUI ever complains about a missing cv2, that's the culprit. It's also the slowest step in the whole pack on long or high-resolution sequences; it's fine for a few hundred frames, just don't expect GPU speeds. Second, temporal pruning is strictly per-pixel, so a pixel that flickers on/off every other frame never accumulates a run - which is exactly the behavior you want, but it means the filter is blind to "shape of the object," only to how long individual pixels stayed lit. The README's usage notes tease a debug_output toggle "when available" - it isn't in the released node, so preview the result with a standard MaskPreview instead of hunting for it.

Install is shared with the rest of the pack: search "ComfyUI Temporal Mask Tools" in ComfyUI Manager, or git clone https://github.com/nomadoor/ComfyUI-Temporal-Mask-Tools into ComfyUI/custom_nodes, restart, and you're done. No models to download, no keys.

In a real workflow it slots in after Temporal Mask Union and before anything video-aware - mask-guided inpainting, compositing, region-consistent generation. Union smooths the flicker, this node scrubs the residue, and what reaches the downstream model is a mask sequence that actually holds still. It's the least glamorous node in the graph, and the one that quietly saves your edit.

CategoryTemporalMask/Operations

Inputs (3)

NameTypeDefaultDescription
mask_batchMASK
min_durationINT21–64Minimum consecutive frames required to keep a pixel active.
min_area_pixelsINT100–1000000Connected components with fewer active pixels than this are removed.

Outputs (1)

NameTypeDescription
Mask BatchMASK