You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could you provide some more detail about how you worked out this list of endianness behaviour, perhaps some Python code to demonstrate the inconsistency?
I understand that 'native' means that the endianness of the environment is used, but what do you mean by 'mode'?
I worked these out by looking at the code, though it seems I got a few wrong, and some of them have mode checks that I missed. By 'mode' I mean it accepts/returns data in the endianness of the image's mode.
I added another test to my branch for creating an image with the color argument and I don't see any error either (other than some problems with "I;16N"). I think it was just putdata() causing the issues.
I think the Image Stats might be wrong for the I;16 modes as well. And some of the extrema for those and other modes seem to be off by one. I've printed out the stats for the Hopper image for each mode: hopper_image_stats.py.txt
For the I;16 modes I believe is due to the histogram calculation not being correct for them.
I was working in Tests/test_imagestat.py, so I used the hopper() function to get the image, which loads "hopper.ppm". Apparently, the images are not quite the same...
ImageStat.Stat.extrema relies on the image histogram function, and simply returns the low and high bins used. This is correct for 8 bit per channel images, but fails for anything else.
So, ultimately, Image.getextrema is a much more efficient and correct function to use.
This relies on the histogram() method, and simply returns the low and high bins used. This is correct for images with 8 bits per channel, but fails for other modes such as I or F. Instead, use getextrema() to return per-band extrema for the image. This is more correct and efficient because, for non-8-bit modes, the histogram method uses getextrema() to determine the bins used.
Activity
radarhere commentedon Nov 30, 2022
Could you provide some more detail about how you worked out this list of endianness behaviour, perhaps some Python code to demonstrate the inconsistency?
I understand that 'native' means that the endianness of the environment is used, but what do you mean by 'mode'?
Yay295 commentedon Nov 30, 2022
I worked these out by looking at the code, though it seems I got a few wrong, and some of them have mode checks that I missed. By 'mode' I mean it accepts/returns data in the endianness of the image's mode.
Yay295 commentedon Nov 30, 2022
Here's a more interesting test:
Yay295 commentedon Dec 26, 2022
I created a branch with some tests: https://github.com/Yay295/Pillow/tree/bytes_tests
There are three failures:
FAILED Tests/test_image.py::TestImageBytes::test_get_pixel[I;16-2] - assert (256, 1284, 770, 1798) == (65535, 65535, 770, 1798)
FAILED Tests/test_image.py::TestImageBytes::test_get_pixel[I;16L-2] - assert (256, 1284, 770, 1798) == (65535, 65535, 770, 1798)
FAILED Tests/test_image.py::TestImageBytes::test_get_pixel[I;16B-2] - assert (1, 1029, 515, 1543) == (511, 65535, 515, 1543)
That test is just:
image.putdata(image.getdata())Also apparently we can't create BGR images with
Image.new()? And there was an error with "I;16N" too: "unknown raw mode for given image mode".radarhere commentedon Dec 26, 2022
I've created PR #6825. With that, tests from bytes_tests pass, as well as your other code examples earlier.
radarhere commentedon Dec 27, 2022
I attempted to test the problem with the
colorargument ofImage.new, but found that it passed on both big and little endian.Would you be able to post code examples of problems apart from
putdata()?Yay295 commentedon Dec 28, 2022
I added another test to my branch for creating an image with the
colorargument and I don't see any error either (other than some problems with "I;16N"). I think it was justputdata()causing the issues.radarhere commentedon Dec 28, 2022
I've created PR #6834 to fix the I;16N problems.
radarhere commentedon Dec 29, 2022
PR #6825 has now been merged. If I;16N is also fixed, does that resolve this issue?
Yay295 commentedon Dec 30, 2022
I think the Image Stats might be wrong for the I;16 modes as well. And some of the extrema for those and other modes seem to be off by one. I've printed out the stats for the Hopper image for each mode: hopper_image_stats.py.txt
For the I;16 modes I believe is due to the histogram calculation not being correct for them.
radarhere commentedon Dec 30, 2022
The following code
gives me
with main and with Pillow 9.3.0. So I don't know what code you used to get
(0, 254)for the I;16 modes in your attachment.Yay295 commentedon Dec 30, 2022
I was working in Tests/test_imagestat.py, so I used the
hopper()function to get the image, which loads "hopper.ppm". Apparently, the images are not quite the same...radarhere commentedon Dec 30, 2022
#1606 (comment)
The issue was resolved by #3661, creating a note at https://pillow.readthedocs.io/en/stable/reference/ImageStat.html#PIL.ImageStat.Stat.extrema
radarhere commentedon Mar 19, 2023
I've created PR #7010 to add support for creating images with BGR;15, BGR;16 and BGR;24, but to drop support for BGR;32 altogether.