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
Tag 262 (PhotometricInterpretation) is changed when saving as a TIFF #4804
Comments
As an explanation of what is happening, the image you have provided has mode 1. This is how we are setting the photometric interpretation when saving. Pillow/src/PIL/TiffImagePlugin.py Line 1446 in 5c9faf0
Pillow/src/PIL/TiffImagePlugin.py Lines 1418 to 1421 in 5c9faf0
So depending on the mode, it will not always be 1. But I agree that we're not using the same value that was set. It controls "the color space of the image data". This is not a random tag that we've just missed - if we were to just flip a switch and set it to 0, it would invert the colors for this case. We could invert the pixels correspondingly, but the value of doing so is not clear - is there any reason you would like it to be the same? |
I am facing the same problem as eliu-alltrust and I think it is a bug in pillow. The reason for the existence of tag 262 is that there is no general agreement on how values in 1-bit images are interpreted. "1" can be seen as "high intensity" = white or as "set a point" = black. Tag 262 specifies which of those two interpretations should be used when reading a file, not whether pixels are to be inverted when writing a file. However, the later is what happens in pillow: I changed the hard coded photometrics value in TiffImagePlugin.py line 1421 to 0 and pillow inverted my image data when saving. It should, however, leave the pixels unchanged regardless of photometrics and write tag 262 with the value specified by the user. |
So there is a specific need for tag 262 to be set to zero for 1-bit images? Ok then, I have created PR #5655 to resolve this. |
What did you do?
save an uncompressed tiff file to group 4 compressed tiff file
What did you expect to happen?
I expected to get a group 4 compressed tiff file and kept all other tags the same as original file
What actually happened?
I got a group 4 compressed tiff file, but Tag 262 (PhotometricInterpretation) was changed from 0 to 1
What are your OS, Python and Pillow versions?
pillowIssue.zip
The text was updated successfully, but these errors were encountered: