-
-
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
Incorrect SampleFormat and BitsPerSample #5850
Comments
In Pillow, we translate input data into a few standard modes. So, for example, we don't have a mode for float64. Instead, we unpack a variety of floating point types into just "F" - Pillow/src/libImaging/Unpack.c Lines 1700 to 1721 in 0bd97c3
See also https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes. It would be rather big change to abandon this idea in order to ensure that all of NumPy's modes could be roundtripped through Pillow. |
I guess the only potential "bug" here is the uint32 -> int32 conversion, there should be no reason not to preserve this? |
@kmilos are you saying that all "I" modes should go back to NumPy as uint32? So in the context of this issue, that would also mean int8, int16 and int32 would also become uint32. |
No, just that there is a potential data loss/(or wraparound) in just uint32->int32 specifically, i.e. Pillow might be missing something like an "U" mode or "I;32U" modifier, or another way to indicate to Numpy how to cast internal int32 back. |
The "I" mode has a range of int32, so it makes sense to me for that to become int32 when converted to NumPy. You specifically called out uint32 -> int32, but I think the same argument would apply to float64 -> float32. There might indeed be data loss - but in the conversion from NumPy to Pillow in the first place, because the original NumPy types have a higher maximum than the Pillow modes. Pillow mostly doesn't retain the information about the rawmode that an image had. Once the information is loaded, it might be transformed. A user might decide to scale the values down, given that int32 has a lower maximum value than uint32. If the user later converted that back to NumPy, they might be surprised that Pillow had remembered the original format of the data. I don't think we should obscure the fact that the range of the values decreased in this process. Also, just to be clear - this issue has nothing to do with the TIFF format, but just concerns the interface between NumPy and Pillow. |
It's not 100% the same - the former has to deal w/ sign and wraparound, the latter doesn't (only precision and range). In any case, yes, the NumPy <-> Pillow interface should be transparently documented with all of its quirks and gotchas. |
I've created PR #7049 to resolve this. |
Images with signed integer data are all incorrectly assumed to be
int32
.uint32
andfloat64
are also incorrectly determined.gives
The text was updated successfully, but these errors were encountered: