Difference Matte (MEC)
Find what moved between two frames — the difference matte that separates subject from plate
- image_a
- image_b
- mask
The classic compositing move: shoot the empty room, then shoot the actor in the room, and subtract one from the other to get the actor. DifferenceMatteMEC is that move, as a node. It computes the per-pixel difference between two images and turns it into a MASK - everything that changed between the two inputs becomes white, everything that stayed the same goes black, with a threshold and softness to control the edge.
It's the natural companion to the pack's CleanPlateExtractor: you use one to build the clean plate, then this one to difference the plate against the live footage and pull exactly the moving element. Same family, one erases, one isolates.
How it works
The math is a per-pixel distance. With the default l2 metric it computes the Euclidean distance across channels (normalized by √3 so a full-spectrum change maps to 1.0); l1 uses mean absolute difference instead. The resulting difference image is thresholded - pixels above threshold become mask white, below go black - and softness creates a smooth ramp around the threshold instead of a hard cliff, so you get feathered edges rather than aliased ones. With softness at zero the mask is a hard binary. It's pure tensor math in nodes/plate_tools.py; no models involved.
The inputs
- image_a and image_b - the two images to compare. Order doesn't matter; the difference is absolute.
- metric -
l2(default) orl1. - threshold (0.05) - how big a change counts as "different."
- softness (0.05) - the edge ramp around the threshold.
Output is a single mask.
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. No dependencies beyond core torch - no models, no downloads. (Skip the pack root's blanket pip install -r requirements.txt over ComfyUI's own torch/numpy.)
Gotchas
The hard constraint is that the two images must be exactly the same shape - the node raises on a shape mismatch, and if your two sources came from different crops or resolutions, fix that upstream before it'll run. The deeper gotcha is alignment: any global difference between the frames - camera motion, exposure change, noise - shows up as noise in the mask. Difference mattes assume a locked-off camera and stable exposure; if your footage isn't, stabilize first (the pack has a Plate Stabilizer for exactly that) and it'll be a hundred times cleaner. Finally, sensor noise means you'll rarely get a pristine black background - that's what the threshold is for, but crank it too high and you start eating real edges. Start at 0.05, look at the mask, tune.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image_a | IMAGE | — | |
| image_b | IMAGE | — | |
| metricopt | COMBO | l2 | 2 options: l2, l1 |
| thresholdopt | FLOAT | 0.0500–1 | — |
| softnessopt | FLOAT | 0.0500–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |