Skip to content
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

ValueError: tile cannot extend outside image #3044

Closed
fowler0503 opened this issue Mar 16, 2018 · 5 comments
Closed

ValueError: tile cannot extend outside image #3044

fowler0503 opened this issue Mar 16, 2018 · 5 comments
Labels
Bug Any unexpected behavior, until confirmed feature.
Milestone

Comments

@fowler0503
Copy link

fowler0503 commented Mar 16, 2018

What did you do?

I'm attempting to load a satellite image from Planet.com by running:
image = Image.open(image_file_name)
pix = image.load()
When my code attempts to run image.load() I receive the above referenced error

What did you expect to happen?

I'm expected the tif image to load to be parsed for vectors

What actually happened?

I receive the error: ValueError: tile cannot extend outside image

What versions of Pillow and Python are you using?

Python 3.6.3 :: Anaconda, Inc
Pillow: 1.1.7

Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as plone, Django, or buildout, try to replicate the issue just using Pillow.
PlanetImage.tif.zip
PlanetImage.tif.zip

>>> from PIL import Image, ImageDraw
>>> image_file_name=('PlanetImage.tif')
>>> image = Image.open(image_file_name)
>>> pix = image.load()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jwfowler/anaconda3/envs/ship_classify/lib/python3.6/site-packages/PIL/TiffImagePlugin.py", line 1053, in load
    return super(TiffImageFile, self).load()
  File "/Users/jwfowler/anaconda3/envs/ship_classify/lib/python3.6/site-packages/PIL/ImageFile.py", line 206, in load
    decoder.setimage(self.im, extents)
ValueError: tile cannot extend outside image
@wiredfool
Copy link
Member

wiredfool commented Mar 22, 2018

The tiff that you're loading has tiles that extend outside the image boundaries. Basically, the reported size of the image is wrong with respect to the encoded data.

There are two things that can be done, either set the image size to the maximum tile extents, or strip out the tile elements that are outside the reported image size:

>>> im = Image.open('issue_3044.tif')
>>> im.tile
[('raw', (0, 0, 128, 128), 2829, ('RGB', 0, 1)), 
('raw', (128, 0, 256, 128), 51981, ('RGB', 0, 1)), 
...
('raw', (2048, 1280, 2176, 1408), 9636621, ('RGB', 0, 1)), 
('raw', (2176, 1280, 2304, 1408), 9685773, ('RGB', 0, 1))]
>>> im.size = (2304, 1408)
>>> im.show()

or

>>> im = Image.open('issue_3044.tif')
>>> im.tile = [e for e in im.tile if e[1][2] < 2181 and e[1][3]<1294]
>>> im.show()

@fowler0503
Copy link
Author

Thanks! That solved it. It also worked when the image was converted to a .png. Does pillow handle .png's differently than .tiff files?

@cgohlke
Copy link
Contributor

cgohlke commented Mar 27, 2018

The tiff that you're loading has tiles that extend outside the image boundaries. Basically, the reported size of the image is wrong with respect to the encoded data.

FWIW, tiles extending outside the image conform to the TIFF 6.0 specification:

Boundary tiles are padded to the tile boundaries. For example, if TileWidth is 64
and ImageWidth is 129, then the image is 3 tiles wide and 63 pixels of padding
must be added to fill the rightmost column of tiles. The same holds for TileLength
and ImageLength. It doesn’t matter what value is used for padding, because good
TIFF readers display only the pixels defined by ImageWidth and ImageLength
and ignore any padded pixels.

@nodegin
Copy link

nodegin commented Jul 19, 2018

Same for this gif image: a28ef5716b5d3f5813d8d08df6c29740f093a635.gif.zip

Looks like the tile is incorrect, reported image.size is (250, 289)
im.tile reports (24, 21, 274, 310)

@hugovk
Copy link
Member

hugovk commented Sep 29, 2018

Fixed by #3227.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

No branches or pull requests

6 participants