Nodes/ComfyUI-CustomNodePacks/Clean Plate Extractor (MEC)
ComfyUI Node

Clean Plate Extractor (MEC)

Erase the moving object from a shot in one step — the clean-plate trick that makes every VFX move easier

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
Clean Plate Extractor (MEC)
  • images
  • exclude_mask
  • clean_plate

A "clean plate" is the version of a shot with the moving thing gone - the background the actor walks in front of, the car that drives past. Every VFX artist knows the value of one: you use it for difference mattes, for painting out the subject, for camera-move reference. CleanPlateExtractorMEC makes it a one-node operation: feed it a batch of frames with the object moving through them, and it returns a single median image where anything that stayed still survives and anything that moved averages away.

The math is beautiful in its simplicity. Over enough frames, a parked background and a moving subject are statistically different: at each pixel, the background value is present in most frames, while the subject occupies that pixel only briefly. The pixelwise median across the batch therefore picks the background value at nearly every pixel. The moving object vanishes. It's the same trick video editors have used since the dawn of compositing, and this node wraps it in torch tensors.

How it works

The node takes the image batch and computes the median along the frame dimension. When you pass an optional exclude_mask, pixels where the mask is ≥ 0.5 are excluded from the median - so if you have a rough matte of the subject (from a segmenter, or even a rough lasso mask), you can tell the median to ignore those pixels entirely and get a cleaner plate faster, with fewer frames needed. For pixels where every sample is excluded, it falls back to the first frame's value so you never get holes. A single-frame input just passes through, which keeps it safe to leave in a template.

The inputs and output

  • images - the frame batch. More frames = cleaner plate; a locked-off (static) camera helps enormously.
  • exclude_mask - optional; pixels ≥ 0.5 are excluded from the median.

Output is a single clean_plate IMAGE.

Installing it

Part of Code2Collapse/ComfyUI-CustomNodePacks. ComfyUI Manager → search "CustomNodePacks", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git

Restart ComfyUI. Pure tensor math - no models, no downloads, no extra dependencies. (Don't run the pack root's blanket pip install -r requirements.txt over ComfyUI's bundled torch/numpy.)

Gotchas

The one hard constraint is alignment: if the camera moves, the background isn't static across frames and the median produces a blurry smudge instead of a clean plate. Pair it with the pack's Plate Stabilizer (which stabilizes a moving shot so the background locks off) or only use it on locked-off footage. The exclude_mask batch size must match the image batch or the node raises - a mismatch is the most common error here. And be honest about frame count: three frames with the subject in all three won't erase it. You want enough frames that the background is a majority at each pixel - a dozen or more frames of movement is the sweet spot.

CategoryMaskEditControl/PlateTools

Inputs (2)

NameTypeDefaultDescription
imagesIMAGE
exclude_maskoptMASKPixels where mask>=0.5 are excluded from the median.

Outputs (1)

NameTypeDescription
clean_plateIMAGE