Skip to content

ValueError: tile cannot extend outside image #3044

Closed

Description

@fowler0503

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

Activity

  1. wiredfool commented on Mar 22, 2018

    @wiredfool
    Member

    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()
  2. fowler0503 commented on Mar 22, 2018

    @fowler0503
    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?

  3. cgohlke commented on Mar 27, 2018

    @cgohlke
    Contributor

    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.
    
  4. added
    Bug
    on Apr 1, 2018
  5. added this to the Future milestone on Apr 1, 2018
  6. nodegin commented on Jul 19, 2018

    @nodegin

    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)

  7. hugovk commented on Sep 29, 2018

    @hugovk
    Member

    Fixed by #3227.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions