openslide / openslide-python

Python bindings to OpenSlide
https://openslide.org/
GNU Lesser General Public License v2.1
375 stars 183 forks source link

openslide.get_thumbnail returns a wrong result #90

Closed VicJasonn closed 4 years ago

VicJasonn commented 4 years ago

Context

Issue type (bug report or feature request): bug report Operating system (e.g. Fedora 24, Mac OS 10.11, Windows 10): Ubuntu 16.04.6 LTS Platform (e.g. 64-bit x86, 32-bit ARM): x86_64 OpenSlide version: openslide-python 1.1.0 Slide format (e.g. SVS, NDPI, MRXS): TIF(more specficly, WSIs of Camelyon16 dataset )

Details

At the beginning, when I used openslide to read a WSI(tif format), it raised an error like this: image

since I found that changing version of Pillow didn't work, then I added this line at the bottom just when I import libraries: image

then it didn't raised error anymore. However, I found it returned a thumbnail of wrong size, I read a WSI and want to get a thumbnail of specific shape, but it got a wrong result:

my code and wrong results: image

what's more, the size of thumbnail doesn't change correctly as the parameters change:

size of original WSI: image

wrong results: image

image

image

I can't figure it out why openslide.get_thunmnail method doesn't return correct results. It is wired. Who can help me? please.

bgilbert commented 4 years ago

The first issue is fixed in OpenSlide Python 1.1.1 (7bd2cdb22fbd6a20c96345dd1539c82cc878244b).

As to the thumbnail size, OpenSlide Python reads from the nearest WSI level and then scales the result to fit within the size you specify. It doesn't stretch the image to fit the aspect ratio you selected. In addition, some WSI formats have uneven scaling in higher-numbered (smaller) levels, which may be contributing to the result you're seeing.