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
Three TIFF tags cause display issues in GIS software #5838
Comments
I suspect that you're much more likely to be losing the geo metadata or converting data types than seeing those tags cause an error. I'd recommend checking the metadata with |
When I use What Pillow version are you using? |
I am using version >>> import PIL
>>> PIL.__version__
'8.4.0' I can see that there is quite a large size difference between my input dem and output dem, so something is happening (66975 byte vs 7210 byte). It just seems a bit weird to me that the output has not lost any tags and gained three new ones, but is way smaller in size. Here is the produced output from the earlier code: I am aware that |
Part of the problem is that StripOffsets, RowsPerStrip and StripByteCounts are not data that just happens to also be in the same file as the image - they are instructions for how to read the image. https://www.awaresystems.be/imaging/tiff/tifftags/rowsperstrip.html
Pillow would be using strips with the intention to create a better image. You might suggest that Pillow shouldn't write images in strips if the supplied tags don't mention it. But what if a user had manually created a list of a few TIFF tags they wanted saved, and hadn't even thought about strips? We would then be punishing them by saving a less-optimal image. |
These three tags are actually mandatory for strip-based TIFF-compliant images, even if you have just the one strip. Your original image is tile-based, and has these mandatory tags instead:
Normally TIFF-compliant readers should be able to deal with both tile-based and strip-based files. One other thing: your code keeps the original tile-based tags, which should be removed when writing as strip-based, try that. The way it is, you end up with an "invalid" TIFF file. |
Maybe this is of relevance? |
Nope, see above. As for the size difference: tile-based will always write full tiles (128x128 in this case) even for your 40x40 image, padded with 0s. No padding is necessary for strip-based writing. 128x128 / (40x40) = 10.24 factor difference you're seeing. |
Pillow should probably include a mechanism for automatic removal of tile-based tags if writing as strips. |
I've created PR #5839 to do that, resolving this. |
When I run my GeoTIFF though Pillow while trying to preserve the TIFF info I end up with 3 additional TIFF tags in the output (
StripOffsets
,RowsPerStrip
,StripByteCounts
). The resulting output GeoTIFF is now displayed incorrectly in the GIS softwareESRI ArcMap
(all cell values are nowNoData
), but is displayed correctly withPillow
orMatplotlib
. The input GeoTIFF image is produced withESRI ArcMap
and does not have the 3 extra TIFF tags.This could of course be an issue with
ESRI ArcMap
, but I believe the 3 Pillow generated TIFF tags might be wrong. They show up as:Input GeoTIFF:
dem_input.zip
The text was updated successfully, but these errors were encountered: