Replies: 1 comment
-
It's just a list of values, yes. Pillow/Tests/test_image_point.py Line 11 in 12022fe Pillow/Tests/test_image_point.py Lines 44 to 45 in 12022fe |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The documentation for
Image.point()
says you can pass it functions or lookup tables.The examples show a simple linear lambda function using multiply and add operators.
However, if I include a divide operator, it all breaks down. For example,
im.point(lambda x: 500 / x)
results inTypeError: unsupported operand type(s) for /: 'int' and '_E'
(My actual formula is somewhat more complex, involving several operators and a logarithm to convert radiated IR into measured temperature)
On the other hand, lookup tables are not supported for float type images, as evidenced by the source code, and I do not wish to lose accuracy by casting to integers.
Happily, I found a concise way to do this:
im.putdata(np.vectorize(my_function)(im.getdata()))
I was intending to post this as a question, but I found my answer as I was providing evidence of the problem. Hopefully this will help someone else who is struggling to use Image.point() in the future.
As a side note, I never found a clear example of what format the lookup table should be. Is it just a list of values, addressed by index?
Beta Was this translation helpful? Give feedback.
All reactions