histolab: error fro reading high resolution image

error message PIL.Image.DecompressionBombError: Image size (693068558 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack.

Description Dear developers,

I am new to image analysis. I want to utilize histolab for tiling some H&E stained images. However, I find it couldn’t handle rather high-resolution data (I guess). The sampled image, I downloaded from https://cf.10xgenomics.com/samples/spatial-exp/1.3.0/Visium_FFPE_Human_Prostate_Cancer/Visium_FFPE_Human_Prostate_Cancer_image.tif.

I wonder do you have any idea of how to solve it?

Best, Kenong

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Anyway @suke18 , this is actually a safety feature included in Pillow; quoting from the documentation at https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.open

To protect against potential DOS attacks caused by “decompression bombs” (i.e. malicious files which decompress into a huge amount of data and are designed to crash or cause disruption by using up a lot of memory), Pillow will issue a DecompressionBombWarning if the number of pixels in an image is over a certain limit, PIL.Image.MAX_IMAGE_PIXELS. This threshold can be changed by setting PIL.Image.MAX_IMAGE_PIXELS. It can be disabled by setting Image.MAX_IMAGE_PIXELS = None. If the number of pixels is greater than twice PIL.Image.MAX_IMAGE_PIXELS, then a DecompressionBombError will be raised instead.

I don’t think it’s safe for us to disable this limit histolab-wide. @ernestoarbitrio any comments?

So, if you trust 100% the source of the data, you can try to change it after importing histolab:

from PIL import Image
Image.MAX_IMAGE_PIXELS = None

Please let me know if this helps!!

Best, Alessia

Thanks for this ^^ I needed it, too.

@alessiamarcolini , Alessia, thank you for figuring this out.

Best, Kenong