EditUtils: Diff Mask lrzjason
Find Exactly What Changed Between Two Images — Without a Naive Pixel Diff
- image1
- image2
- mask
Take an original photo and an edited version, and you usually want to know where they differ - to inspect the edit, to build a mask for a second pass, or to feed selective inpainting. A naive per-pixel difference catches obvious changes but drowns in noise and misses subtle re-lighting. DiffMask_EditUtils is a proper difference-mask generator: it blends a frequency-domain comparison with the plain pixel difference, then cleans the result with morphology and blur. It's the kind of tool that sounds like overkill until the first time it finds the change a plain diff couldn't.
The inputs, two images plus five knobs: image1, image2, then threshold (binarization cutoff, default 0.05), blur_radius (Gaussian smoothing, default 5), erode_size (default 3), dilate_size (default 3), use_frequency (default on), highpass_sigma (default 10), and freq_weight (default 0.7). Output: a single mask.
Here's what actually happens, because it's smarter than you'd expect from a "diff" node. Both images are converted to luminance, then the pipeline runs three stages. Frequency domain: with use_frequency on, it takes an FFT of each image, subtracts them, and runs the difference through a Gaussian high-pass filter - meaning it amplifies the high-frequency differences (textures, edges, small displacements) that survive a global brightness shift. Blend and threshold: that frequency difference gets weighted by freq_weight against the plain pixel difference, and anything above threshold becomes mask. Cleanup: erosion followed by dilation (a morphological opening, killing isolated specks) and a Gaussian blur to soften the edges into something usable as an inpainting or masking input.
The defaults are tuned, and the tooltips tell you which way to turn each one. highpass_sigma smaller = emphasizes higher frequencies harder (good for finding fine texture edits); freq_weight down = trust the raw pixel diff more. If your mask is noisy confetti, raise threshold or erode_size; if it's missing subtle changes, raise freq_weight or lower highpass_sigma. The one hard rule: the two images must be the same shape, and the node raises an error rather than silently resizing - so feed it outputs of the same pipeline, or resize first.
The natural home for this in an edit workflow is after you've generated: original in image1, edited result in image2, and the mask tells you what the model actually changed. From there you can mask-compare, threshold into a second edit, or just audit whether the change landed where you asked. It's honestly a niche utility - you'll reach for it when auditing edits, not on every run - but when the question is "what moved between these frames?", it answers better than any naive diff. Install: ComfyUI Manager (search "EditUtils") or git clone https://github.com/lrzjason/ComfyUI-EditUtils into custom_nodes, restart. Pure torch/FFT, no dependencies.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image1 | IMAGE | — | |
| image2 | IMAGE | — | |
| threshold | FLOAT | 0.0500–1 | Binarization threshold (0-1) |
| blur_radius | INT | 50–50 | Gaussian blur kernel size (0 means no blur) |
| erode_size | INT | 30–20 | Erosion kernel size (0 means no erosion) |
| dilate_size | INT | 30–20 | Dilation kernel size (0 means no dilation) |
| use_frequency | BOOLEAN | true | Enable frequency-domain high-pass filtering (strongly recommended) |
| highpass_sigma | FLOAT | 10.01–100 | High-pass filter cutoff frequency (sigma), smaller values emphasize higher frequencies |
| freq_weight | FLOAT | 0.700–1 | Weight for frequency-domain difference, remaining weight goes to original pixel difference |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |