-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return boolean from ImageMath lambda_eval and unsafe_eval comparison operations #8227
Conversation
Is this a breaking change? |
For ImageMath expressions that involve equality or comparison checks, yes. Here are some alternative ways forward.
|
@python-pillow/pillow-team What do you think? |
Probably one of the few good times to make a breaking change (from 10.x to 11) and worst case you could follow up with options 1 or 2 in |
We've usually been cautious about breaking changes without at least a year of deprecations. I would prefer alternative 1 or 2. This PR is to improve the API, but motivated by adding type hints, and not user demand, so I would err on bring cautious. |
Ok, I've pushed a commit to implement 2 - only changing the behaviour for |
I've created #8464 to implement 1 - I've realised that the current form does have conceivably useful functionality. For example, you can invert the upper left quadrant of hopper. >>> from PIL import Image, ImageMath
>>> im = Image.open("Tests/images/hopper.png").convert("1")
>>> b = Image.new("1", (128, 128))
>>> for x in range(64):
... for y in range(64):
... b.putpixel((x, y), 1)
...
>>> ImageMath.eval("(A != B) * 65535", A=im, B=b).save("out.png") |
currently gives
<PIL.Image.Image image mode=I size=1x1 at 0x1047906E0>
This PR suggests changing the output to a more meaningful
True
.==
,!=
,<
,<=
,>
,>=
,equal()
andnotequal()
would all now return boolean results.