the shape of image from DeepZoomGenerator.get_tile is inconsistent
4pygmalion opened this issue · 1 comments
Operating system
ubuntu 20.04
Platform
x86_64 x86_64 x86_64 GNU/Linux
OpenSlide Python version
1.3.1
OpenSlide version
4.0.0
Slide format
TIFF
Issue details
I worked on the Camelyon16 dataset, which focuses on lymph node metastasis in breast cancer. In this process, I initialized the DeepZoomGenerator using a tile size of 512. Subsequently, I retrieved a tile using the following code: generator.get_tile(generator.level_count-LEVEL-1, (80, 150))
.
However, I noticed that the returned image shape is (544, 544, 3) instead of the expected (512, 512, 3). There are a couple of aspects that require clarification:
1) Size Discrepancy:
It's puzzling why the size of the returned image is not (512, 512, 3). There may be some internal processing or default behaviors in the DeepZoomGenerator that lead to this discrepancy.
2) Level Reversal:
Regarding the reversal of the level argument, in Openslide.read_region the argument level is typically 0 for high resolution, whereas in DeepZoomGenerator.get_tile it is 0 for low resolution.
from openslide.deepzoom import DeepZoomGenerator
LEVEL = 1
slide = OpenSlide(slide_path)
generator = DeepZoomGenerator(slide, tile_size=512, overlap=16, limit_bounds=True)
generator_zoom_level = generator.level_count-LEVEL-1
cols, rows = generator.level_tiles[generator_zoom_level]
print(cols, rows)
res = generator.get_tile_coordinates(generator.level_count-LEVEL-1, (81, 155))
image = generator.get_tile(generator.level_count-LEVEL-1, (81, 155))
np.array(image).shape
96 209
(544, 544, 3)
1) Size Discrepancy: It's puzzling why the size of the returned image is not (512, 512, 3). There may be some internal processing or default behaviors in the DeepZoomGenerator that lead to this discrepancy.
You've configured DeepZoomGenerator
with an overlap of 16 pixels:
DeepZoomGenerator(slide, tile_size=512, overlap=16, limit_bounds=True)
Interior tiles will have overlaps on both sides of the tile, and 512 + 16 + 16 = 544, which matches the tile size you're seeing.
2) Level Reversal: Regarding the reversal of the level argument, in Openslide.read_region the argument level is typically 0 for high resolution, whereas in DeepZoomGenerator.get_tile it is 0 for low resolution.
Yes, that's correct. OpenSlide defines level 0 as the highest-resolution level, while the Deep Zoom specification defines it as the lowest-resolution level. In DeepZoomGenerator
, level
arguments consistently use Deep Zoom's level numbering.