Skip to content

Truncated/corrupted jpeg2000 image #3946

@Pazaak

Description

@Pazaak

Hi, I have a batch of images like this and I want them converted to a numpy array:
https://drive.google.com/open?id=1hx_s1LZV48ID89CFaTzE3vjUTXN1IcGl

The images seem to be jpeg2000 and truncated. Trying to load them without LOAD_TRUNCATED_IMAGES gives me the usual exception:

from PIL import Image
a = Image.open('broken.jpg').convert("RGB")

OSError: broken data stream when reading image file

Using LOAD_TRUNCATED_IMAGES = True

from PIL import Image, ImageFile
import numpy as np
ImageFile.LOAD_TRUNCATED_IMAGES = True
a = np.asarray(Image.open('broken.jpg').convert("RGB"))
print(np.sum(a))

Gives a zero sum of the array, indicating that the image is not properly loaded. I was expecting an array containing the RGB information of the image.

  • OS: Ubuntu 16.04
  • Python: 3.68
  • Pillow: 6.1.0

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions