-
Notifications
You must be signed in to change notification settings - Fork 183
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
deepzoom_tile.py creates tiles with inconsistent width or height #111
Comments
Update: I found It seems that def get_tile(self, level, address):
"""Return an RGB PIL.Image for a tile.
level: the Deep Zoom level.
address: the address of the tile within the level as a (col, row)
tuple."""
# Read tile
args, z_size = self._get_tile_info(level, address) # z_size=(212, 8)
tile = self._osr.read_region(*args) # tile.size=(423, 14)
# Apply on solid background
bg = Image.new('RGB', tile.size, self._bg_color)
tile = Image.composite(tile, bg, tile)
# Scale to the correct size
if tile.size != z_size:
tile.thumbnail(z_size, Image.ANTIALIAS) # tile.size=(212, 7), it's smaller than z_size
return tile DeepZoom users would expect tiles in the same row to have the same height, and tiles in the same column to have the same width. |
Is there any update or fix for this ? |
I am having the same issue with viewing tiff files. Some generated tiles are white with checker lines across it, like shown above. Weirdly, this only seems to happen on certain 'levels' of the image, while others are unaffected. |
I solved it (for my needs) by modifying /Lib/site-packages/openslide/deepzoom.py def get_tile(self, level, address, method="fill"):
"""Return an RGB PIL.Image for a tile.
level: the Deep Zoom level.
address: the address of the tile within the level as a (col, row)
tuple.
method: "fill" - fills the space of partial images and the target image size
"rescale" - scales partial images to the target size
"""
# Read tile
args, z_size = self._get_tile_info(level, address)
tile = self._osr.read_region(*args)
# Apply on solid background
bg = Image.new(mode='RGBA', size=(self._z_t_downsample, self._z_t_downsample), color=self._bg_color)
if method=="fill":
tile = Image.composite(tile, bg, tile)
# Scale to the correct size
if tile.size != z_size:
# Image.Resampling added in Pillow 9.1.0
# Image.LANCZOS removed in Pillow 10
# tile.thumbnail(z_size, getattr(Image, 'Resampling', Image).LANCZOS)
tile.thumbnail(tile.size, getattr(Image, 'Resampling', Image).LANCZOS) # fill
if method=="rescale":
tile_new = Image.composite(tile, bg, tile)
# Scale to the correct size
if tile_new.size != z_size:
tile = tile.resize(tile_new.size, Image.ANTIALIAS) # scale
return tile now one can choose to fill the space or to rescale the partial image by image_tiles = DeepZoomGenerator(image_slides, tile_size=tile_size, overlap=0, limit_bounds=False)
image_tiles .get_tile(level, (col, row), method="fill") or image_tiles = DeepZoomGenerator(image_slides, tile_size=tile_size, overlap=0, limit_bounds=False)
image_tiles .get_tile(level, (col, row), method="rescale") |
Context
Issue type (bug report or feature request): bug report
Operating system (e.g. Fedora 24, Mac OS 10.11, Windows 10): Windows 10
Platform (e.g. 64-bit x86, 32-bit ARM): 64-bit x86
OpenSlide Python version (
openslide.__version__
): 1.1.2OpenSlide version (
openslide.__library_version__
): 3.4.1Slide format (e.g. SVS, NDPI, MRXS): TIFF
Details
I have some tiles converted using OpenSlide's
deepzoom_tile.py
from TIFF, but I noticed that they have inconsistent width or height.For example, I convert the CMU-1.tiff (from here) to DZI format using libvips, the tiles with level=10 will have the following size:
In particular, the tiles in the last column have a width of 212px and the tiles in the last row have a height of 8px.
On the other hand, when converted using
deepzoom_tile.py
, the tiles in the last row and the last column are generated with different widths and heights. In particular, the last column contains tiles of different widths.The tiles in the last column have both 211px and 212px tile widths. (Also, the height of the tiles in the last row seems to be different from libvips.)
I'm confused by this behavior; what tile size should OpenSlide return in this case?
The text was updated successfully, but these errors were encountered: