Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

garbled tiles from CAMELYON16 dataset using tiffslide but not openslide #86

Open
kaczmarj opened this issue Jul 18, 2024 · 6 comments
Open
Labels
workaround-exists Issue contains a working fix

Comments

@kaczmarj
Copy link
Contributor

i have come across unexpected behavior when reading a tile from the CAMELYON16 dataset, slide test_019.tif. please see code to reproduce below.

download image test_019.tif using:

# python -m pip install awscli
aws s3 cp --no-sign-request s3://camelyon-dataset/CAMELYON16/images/test_019.tif .

Tile read using tiffslide

import tiffslide

x, y = 166888, 50248
s = 566
tslide = tiffslide.TiffSlide("test_019.tif")
tslide.read_region((x, y), level=0, size=(s, s))

image

Tile read using openslide

import openslide

x, y = 166888, 50248
s = 566
oslide = openslide.OpenSlide("test_019.tif")
oslide.read_region((x, y), level=0, size=(s, s))

image

takeaway

as you can see, the tile read using tiffslide is different from that using openslide. i wonder if jpeg2000 compression is an issue here?

@kaczmarj
Copy link
Contributor Author

i suspect the jpeg2000 compression has something to do with this, because i cannot reproduce in images that have other compression schemes.

the camelyon16 dataset uses jpeg2000.

@kaczmarj
Copy link
Contributor Author

kaczmarj commented Jul 18, 2024

the difference is much more pronounced in test_034

# Download the image
aws s3 cp --no-sign-request s3://camelyon-dataset/CAMELYON16/images/test_034.tif .
x, y = 56606, 43386
s = 566

tslide = tiffslide.TiffSlide("test_034.tif")
oslide = openslide.OpenSlide("test_034.tif")

tslide.read_region((x, y), level=0, size=(s, s))
oslide.read_region((x, y), level=0, size=(s, s))

TiffSlide

image

Openslide

image

@ap--
Copy link
Collaborator

ap-- commented Jul 18, 2024

Interesting... Seems there is something different about the lowest level in the tif file.

This is broken in tifffile<=2024.4.24 and is fixed with tifffile>=2024.5.3

https://github.com/cgohlke/tifffile/blob/7230baf84200203c7d3f50f46324093cd71013fb/CHANGES.rst?plain=1#L32-L35

import tiffslide
import PIL.Image

s = tiffslide.open_slide("./test_034.tif")

PIL.Image.fromarray(s.zarr_group[1][::32,::32,:]).save("out1.png")
PIL.Image.fromarray(s.zarr_group[0][::64,::64,:]).save("out0.png")

level=1

out1

level=0 (tifffile<=2024.4.24)

out0

level=0 (tifffile>=2024.5.3)

out0c

@ap-- ap-- added the workaround-exists Issue contains a working fix label Jul 18, 2024
@kaczmarj
Copy link
Contributor Author

that's great! thanks for this. i'm glad the fix is already out. feel free to close the issue if there is nothing else to do.

@ap--
Copy link
Collaborator

ap-- commented Jul 18, 2024

Until tiffslide requires a newer tifffile version we'll keep this open so that people find it more easily.

@ap--
Copy link
Collaborator

ap-- commented Jul 18, 2024

And thank you for reporting, and providing a reproducible example ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
workaround-exists Issue contains a working fix
Projects
None yet
Development

No branches or pull requests

2 participants