Skip to content

Commit bb0a469

Browse files
authored
Merge pull request #127 from mducducd/fix/supertile-size
Fix/ compute supertile size The supertile size formula (micron) derives the size from slide pixels * MPP. It can be affected by rounding (np.ceil) and slight metadata inaccuracies in slide_mpp. In some cases, this leads to off-by-one errors or out-of-bounds issues when reading regions. It can be fixed by: - If the slide’s MPP metadata is available, use the pixel-based formula. - If mpp metadata is missing and an approximated mpp is used instead (may cause inaccurate or inconsistent), use the tile-based formula (tile micron * num_tiles in supertile) to avoid rounding errors and out-of-bounds issues.
2 parents f663a7e + a3cf270 commit bb0a469

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/stamp/preprocessing/tiling.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ def _supertiles(
314314
)
315315
supertile_size_tile_px = TilePixels(tile_size_px * len_of_supertile_in_tiles)
316316

317+
if default_slide_mpp is not None:
318+
supertile_size_um = Microns(tile_size_um * len_of_supertile_in_tiles)
319+
else:
320+
supertile_size_um = Microns(supertile_size_slide_px * slide_mpp)
321+
317322
with futures.ThreadPoolExecutor(max_workers) as executor:
318323
futs = []
319324
for coords_slide_px in _foreground_coords(
@@ -334,7 +339,7 @@ def _supertiles(
334339
x=Microns(x_slide_px * slide_mpp),
335340
y=Microns(y_slide_px * slide_mpp),
336341
),
337-
size=Microns(supertile_size_slide_px * slide_mpp),
342+
size=supertile_size_um,
338343
),
339344
x_slide_px=coords_slide_px.x,
340345
y_slide_px=coords_slide_px.y,

0 commit comments

Comments
 (0)