ImageBlend node's "difference" mode loses all negative results due to missing abs()
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
The difference blend mode in comfy_extras/nodes_post_processing.py blend images node is implemented as:
```
elif mode == "difference":
return img1 - img2
```
followed by torch.clamp(blended_image, 0, 1).
This is inconsistent with the standard "Difference" blend mode used in Photoshop, GIMP, Krita, Substance, etc., which is abs(img1 - img2). Without the abs(), any pixel where img1 < img2 gets clamped to exactly 0 instead of showing the magnitude of the difference.
This isn't just an edge case — for use cases where image1 is expected to be consistently smaller than image2 (e.g. computing E[X]² - E[X²] as an (incorrectly-ordered) intermediate step toward a local variance map), the output is deterministically all-black across 100% of pixels, with no way to recover the signal downstream.
Fix?
```
elif mode == "difference":
return torch.abs(img1 - img2)
```
Expected behavior: difference mode should return the absolute value of the pixel-wise difference, matching every other major image editor's convention.
Redacted with the help of Claude/chatGPT, I hope this is accurate and helpful.
Contributor guide
Research direction
Open comfy_extras/nodes_post_processing.py and inspect the ImageBlend node's difference mode and its subsequent clamping. Change the mode so it preserves the absolute pixel-wise difference, then verify that both img1 < img2 and img1 > img2 produce the corresponding nonnegative difference rather than clamping one direction to zero.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100