LayerMask: MaskByDifferent(Advance)
Turn what changed between two images into a mask
- image_1
- image_2
- mask
MaskByDifferent does exactly what the name says: give it two images, and it computes the pixel difference between them and outputs that as a mask. No AI model, no segmentation, no API - it's a straightforward diff, which makes it fast and completely predictable, and also means it's only as good as the two images you feed it actually lining up.
Where this is actually useful
The obvious case is isolating what an edit changed. Run an inpaint or an img2img pass, keep both the before and after, feed them here, and you get a mask of exactly the region that moved - handy for a second, more targeted pass on just the changed area, or for verifying an edit didn't touch anything it shouldn't have. It's also a reasonable way to find "what's different" between two near-identical renders (same seed, one changed element) without hand-painting a mask.
It is not a segmentation tool - it has no idea what an "object" is, only what pixels changed. Camera shake, compression artifacts, or slight resampling between two otherwise-identical images will all show up as noise in the diff.
The inputs and outputs that matter
image_1/image_2- required, the pair to compare. They need to be the same size and reasonably aligned; this isn't a registration tool.gain(default 1.5, range 0.1–100) - amplifies the difference signal. Push this up if a real but subtle change (a slight color shift, a faint added detail) isn't showing up strongly enough in the mask.fix_gap(default 4, range 0–32) - patches small internal holes in the resulting mask; higher values repair bigger gaps, useful when a diff comes out speckled instead of one solid region.fix_threshold(default 0.75, range 0.01–0.99) - the threshold that controls whatfix_gapconsiders worth filling.main_subject_detect(default off) - when enabled, the node tries to ignore differences outside the main subject, which is the setting to reach for if background noise (lighting flicker, compression) is polluting an otherwise-clean diff of a foreground change.
Output is a single mask.
Installing it
ComfyUI Manager: search "ComfyUI Layer Style Advance". Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle_Advance.git
Run install_requirements.bat (or the manual pip/whl steps for a portable install) and restart. This node is pure image-math - no model to download, no key to configure - so once the base pack is installed and importing cleanly, this one is ready to go.
Common issues
Mask is mostly noise, no clean region. Almost always means the two images aren't as aligned as you think - even a one-pixel shift between "before" and "after" will diff as changed everywhere. Make sure both images came from the same canvas/resolution without any resize or crop happening in between.
Real change isn't showing up. Raise gain. A subtle edit (small color adjustment, thin added line) can sit below the default sensitivity.
Mask has holes in an otherwise-solid region. Raise fix_gap, and check fix_threshold isn't set so high that borderline pixels get excluded from the fill.
Background differences swamp the actual subject change. Turn on main_subject_detect - this is specifically what it's for, ignoring diff noise outside the main subject rather than making you crop or mask the comparison region manually first.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image_1 | IMAGE | — | |
| image_2 | IMAGE | — | |
| gain | FLOAT | 1.50.1–100 | — |
| fix_gap | INT | 40–32 | — |
| fix_threshold | FLOAT | 0.750.01–0.99 | — |
| main_subject_detect | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |