0

I'm using OpenSlide and PIL to open slides and resize them. For some of the slides, the resulting images are partly black. To reproduce the error, use this slide and this script:

def slide_to_scaled_pil_image(slide, SCALE_FACTOR=32):
  """
  Convert a WSI training slide to a scaled-down PIL image.
  Args:
    slide: An OpenSlide object.
  Returns:
    Tuple consisting of scaled-down PIL image, original width, original height, new width, and new height.
  """

  large_w, large_h = slide.dimensions
  new_w = math.floor(large_w / SCALE_FACTOR)
  new_h = math.floor(large_h / SCALE_FACTOR)
  level = slide.get_best_level_for_downsample(SCALE_FACTOR)
  whole_slide_image = slide.read_region((0, 0), level, slide.level_dimensions[level])
  whole_slide_image = whole_slide_image.convert("RGB")
  img = whole_slide_image.resize((new_w, new_h), PIL.Image.BILINEAR)
  return img, large_w, large_h, new_w, new_h

img = openslide.OpenSlide(PATH_TO_SLIDE)
ds_img, large_w, large_h, new_w, new_h = slide_to_scaled_pil_image(img, SCALE_FACTOR=SCALE_FACTOR)

So if I use different SCALE_FACTOR I end up with a different result (ds_img). SCALE_FACTOR=32 produces this: damaged slide

while SCALE_FACTOR=64 produces this: normal slide

What is the problem here? Is there a way to overcome this issue if I need to use SCALE_FACTOR=32?

Some student
  • 131
  • 2
  • 13

1 Answers1

0

I'm using exactly the same tiling pipeline you're using (and on the same TCGA data) and found the same weird results.

What fixed it to me was to upgrade (download/build) the latest version of the pixman library to 0.40.0. You will need to upgrade the corresponding Python modules as well, especially pillow and pixman.

There are tons of discussion here - https://github.com/openslide/openslide/issues/291 - and throughout GitHub (just follow the threads).