diff --git a/dlup/background.py b/dlup/background.py index 6224f837..b69910d0 100644 --- a/dlup/background.py +++ b/dlup/background.py @@ -112,13 +112,15 @@ def _is_foreground_numpy( x, y, w, h, mpp = region mask_size = np.array(background_mask.shape[:2][::-1]) + + region_view = slide_image.get_scaled_view(slide_image.get_scaling(mpp)) _background_mask = PIL.Image.fromarray(background_mask) # Type of background_mask is Any here. # The scaling should be computed using the longest edge of the image. background_size = (_background_mask.width, _background_mask.height) - region_size = slide_image.get_scaled_size(slide_image.get_scaling(mpp)) + region_size = region_view.size max_dimension_index = max(range(len(background_size)), key=background_size.__getitem__) scaling = background_size[max_dimension_index] / region_size[max_dimension_index] scaled_region = np.array((x, y, w, h)) * scaling