imi-bigpicture / wsidicom

Python package for reading DICOM WSI file sets.
Apache License 2.0
34 stars 6 forks source link

PIL.UnidentifiedImageError: cannot identify image file #135

Closed psavery closed 11 months ago

psavery commented 11 months ago

Do you know why this error is occurring? Here is a reproducer:

from wsidicom import WsiDicom, WsiDicomWebClient

url = 'https://idc-external-006.uc.r.appspot.com/dcm4chee-arc/aets/DCM4CHEE/rs'
study_uid = '1.3.6.1.4.1.5962.99.1.2447135355.1068687300.1625944806011.3.0'
series_uid = '1.3.6.1.4.1.5962.99.1.2447135355.1068687300.1625944806011.2.0'

client = WsiDicomWebClient.create_client(url)

slide = WsiDicom.open_web(client, study_uid, series_uid)

slide.read_region((1920, 1920), 4, (1067, 1017))

I get this error:

Traceback (most recent call last):
  File "/home/patrick/test.py", line 11, in <module>
    slide.read_region((1920, 1920), 4, (1067, 1017))
  File "/home/patrick/virtualenvs/histomics/src/wsidicom/wsidicom/wsidicom.py", line 400, in read_region
    image = wsi_level.get_region(scaled_region, z, path, threads)
  File "/home/patrick/virtualenvs/histomics/src/wsidicom/wsidicom/group/group.py", line 318, in get_region
    image = instance.image_data.stitch_tiles(region, path, z, threads)
  File "/home/patrick/virtualenvs/histomics/src/wsidicom/wsidicom/instance/image_data.py", line 525, in stitch_tiles
    self._paste_tiles(
  File "/home/patrick/virtualenvs/histomics/src/wsidicom/wsidicom/instance/image_data.py", line 576, in _paste_tiles
    pool.map(thread_paste, tile_region.chunked_iterate_all(threads))
  File "/home/patrick/virtualenvs/histomics/src/wsidicom/wsidicom/thread.py", line 41, in map
    return (item for item in list(map(fn, *iterables)))
  File "/home/patrick/virtualenvs/histomics/src/wsidicom/wsidicom/instance/image_data.py", line 568, in thread_paste
    for tile_point, tile in zip(
  File "/home/patrick/virtualenvs/histomics/src/wsidicom/wsidicom/web/wsidicom_web_image_data.py", line 102, in get_decoded_tiles
    yield Image.open(io.BytesIO(frame))
  File "/home/patrick/virtualenvs/histomics/lib/python3.9/site-packages/PIL/Image.py", line 3298, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f4aadc35680>

Note that this example contains uncompressed data.

erikogabrielsson commented 11 months ago

Looks like I forgot to change to the new decoder at this line. Will fix this tomorrow.