MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / get_valid_patch_size

Function get_valid_patch_size

monai/data/utils.py:341–352  ·  view source on GitHub ↗

Given an image of dimensions `image_size`, return a patch size tuple taking the dimension from `patch_size` if this is not 0/None. Otherwise, or if `patch_size` is shorter than `image_size`, the dimension from `image_size` is taken. This ensures the returned patch size is within the bou

(image_size: Sequence[int], patch_size: Sequence[int] | int | np.ndarray)

Source from the content-addressed store, hash-verified

339
340
341def get_valid_patch_size(image_size: Sequence[int], patch_size: Sequence[int] | int | np.ndarray) -> tuple[int, ...]:
342 """
343 Given an image of dimensions `image_size`, return a patch size tuple taking the dimension from `patch_size` if this is
344 not 0/None. Otherwise, or if `patch_size` is shorter than `image_size`, the dimension from `image_size` is taken. This ensures
345 the returned patch size is within the bounds of `image_size`. If `patch_size` is a single number this is interpreted as a
346 patch of the same dimensionality of `image_size` with that size in each dimension.
347 """
348 ndim = len(image_size)
349 patch_size_ = ensure_tuple_size(patch_size, ndim)
350
351 # ensure patch size dimensions are not larger than image dimension, if a dimension is None or 0 use whole dimension
352 return tuple(min(ms, ps or ms) for ms, ps in zip(image_size, patch_size_))
353
354
355def dev_collate(batch, level: int = 1, logger_name: str = "dev_collate"):

Callers 7

randomizeMethod · 0.90
randomizeMethod · 0.90
sliding_window_inferenceFunction · 0.90
iter_patch_slicesFunction · 0.85
dense_patch_slicesFunction · 0.85
iter_patch_positionFunction · 0.85
iter_patchFunction · 0.85

Calls 2

ensure_tuple_sizeFunction · 0.90
minFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…