Value Error In Reading Tif Image With Pil In Python?
Solution 1:
This is because there is an error in the image encoding; the tiles in the TIF file actually do extend outside the image. You can confirm this by viewing the tiles:
img.tile
which will output something like:
[('tiff_lzw', (0, 0, 240, 240), 16, 'RGB'),
('tiff_lzw', (240, 0, 480, 240), 94905, 'RGB'),
...
('tiff_lzw', (720, 960, 960, 1200), 1711985, 'RGB'),
('tiff_lzw', (960, 960, 1200, 1200), 1730566, 'RGB')]
In the case of my example above, the image dimensions were 1000x1000 pixels, but clearly the tiles extend to 1200x1200. You can either crop the image to the expected size (losing some information), or expand the image size to include all the tiles. See examples here:
https://github.com/python-pillow/Pillow/issues/3044
i.e., im.size = (1000, 1000) or im.tile = [e for e in im.tile if e[1][2] < 1200 and e[1][3] < 1200]
Solution 2:
The problem is that PIL wants to see a ".tiff" at the end of the file name. You have ".tif". The solution is to rename your file to "test.tiff".
Post a Comment for "Value Error In Reading Tif Image With Pil In Python?"