From fc861f67b3ca0b2e4578e2411611c334d106680d Mon Sep 17 00:00:00 2001 From: Behrooz <3968947+drbeh@users.noreply.github.com> Date: Wed, 17 Nov 2021 18:13:21 +0000 Subject: [PATCH] Fix casting for tile step Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com> --- .../apps/pathology/transforms/spatial/array.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/monai/apps/pathology/transforms/spatial/array.py b/monai/apps/pathology/transforms/spatial/array.py index e08ac7f46f..56927a8033 100644 --- a/monai/apps/pathology/transforms/spatial/array.py +++ b/monai/apps/pathology/transforms/spatial/array.py @@ -9,7 +9,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Optional, Sequence, Tuple, Union, cast +from typing import Optional, Sequence, Tuple, Union import numpy as np import torch @@ -113,14 +113,16 @@ def __init__( ): self.tile_count = tile_count self.tile_size = tile_size - self.step = step self.random_offset = random_offset self.pad_full = pad_full self.background_val = background_val self.filter_mode = filter_mode - if self.step is None: - self.step = self.tile_size # non-overlapping grid + if step is None: + # non-overlapping grid + self.step = self.tile_size + else: + self.step = step self.offset = (0, 0) self.random_idxs = np.array((0,)) @@ -131,7 +133,6 @@ def __init__( def randomize(self, img_size: Sequence[int]) -> None: c, h, w = img_size - tile_step = cast(int, self.step) self.offset = (0, 0) if self.random_offset: @@ -147,8 +148,8 @@ def randomize(self, img_size: Sequence[int]) -> None: h = h + pad_h w = w + pad_w - h_n = (h - self.tile_size + tile_step) // tile_step - w_n = (w - self.tile_size + tile_step) // tile_step + h_n = (h - self.tile_size + self.step) // self.step + w_n = (w - self.tile_size + self.step) // self.step tile_total = h_n * w_n if self.tile_count is not None and tile_total > self.tile_count: @@ -160,7 +161,6 @@ def __call__(self, image: np.ndarray) -> np.ndarray: # add random offset self.randomize(img_size=image.shape) - tile_step = cast(int, self.step) if self.random_offset and (self.offset[0] > 0 or self.offset[1] > 0): image = image[:, self.offset[0] :, self.offset[1] :] @@ -177,7 +177,7 @@ def __call__(self, image: np.ndarray) -> np.ndarray: ) # extact tiles - xstep, ystep = tile_step, tile_step + xstep, ystep = self.step, self.step xsize, ysize = self.tile_size, self.tile_size clen, xlen, ylen = image.shape cstride, xstride, ystride = image.strides