Skip to content

Allow floating point constants in ImageMath operations - #10218

Merged
radarhere merged 2 commits into
python-pillow:mainfrom
vera-rubin:fix/imagemath-float-constants
Oct 16, 2026
Merged

radarhere merged 2 commits into
python-pillow:mainfrom
vera-rubin:fix/imagemath-float-constants

Conversation

@vera-rubin

Copy link
Copy Markdown
Contributor

ImageMath.lambda_eval raises TypeError: color must be int or single-element tuple when we add 0.5 to an L image. The documentation says this should produce an F image, so a pixel of 10 should become 10.5.

from PIL import Image, ImageMath

a = Image.new("L", (1, 1), 10)
out = ImageMath.lambda_eval(lambda args: args["a"] + 0.5, a=a)
print(out.mode, out.getpixel((0, 0)))

Changes proposed in this pull request:

We now create integer scalar images only for integer constants, allowing floats to use the existing promotion to mode F.

We checked the regression, both existing ImageMath suites, and the Pillow selftest.

Tested with Pillow 13.0.0.dev0 (bc7e6f5), Python 3.12.3.

— ChipLab

@radarhere radarhere added the 🤖-assisted AI-assisted label Oct 16, 2026
@radarhere
radarhere enabled auto-merge (squash) October 16, 2026 07:52
@radarhere
radarhere merged commit f4b0219 into python-pillow:main Oct 16, 2026
66 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖-assisted AI-assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants