MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / DivisiblePad

Class DivisiblePad

monai/transforms/croppad/array.py:298–342  ·  view source on GitHub ↗

Pad the input data, so that the spatial sizes are divisible by `k`. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information.

Source from the content-addressed store, hash-verified

296
297
298class DivisiblePad(Pad):
299 """
300 Pad the input data, so that the spatial sizes are divisible by `k`.
301
302 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
303 for more information.
304 """
305
306 backend = SpatialPad.backend
307
308 def __init__(
309 self,
310 k: Sequence[int] | int,
311 mode: str = PytorchPadMode.CONSTANT,
312 method: str = Method.SYMMETRIC,
313 lazy: bool = False,
314 **kwargs,
315 ) -> None:
316 """
317 Args:
318 k: the target k for each spatial dimension.
319 if `k` is negative or 0, the original size is preserved.
320 if `k` is an int, the same `k` be applied to all the input spatial dimensions.
321 mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``,
322 ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``}
323 available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}.
324 One of the listed string values or a user supplied function. Defaults to ``"constant"``.
325 See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html
326 https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html
327 method: {``"symmetric"``, ``"end"``}
328 Pad image symmetrically on every side or only pad at the end sides. Defaults to ``"symmetric"``.
329 lazy: a flag to indicate whether this transform should execute lazily or not. Defaults to False.
330 kwargs: other arguments for the `np.pad` or `torch.pad` function.
331 note that `np.pad` treats channel dimension as the first dimension.
332
333 See also :py:class:`monai.transforms.SpatialPad`
334 """
335 self.k = k
336 self.method: Method = Method(method)
337 super().__init__(mode=mode, lazy=lazy, **kwargs)
338
339 def compute_pad_width(self, spatial_shape: Sequence[int]) -> tuple[tuple[int, int]]:
340 new_size = compute_divisible_spatial_size(spatial_shape=spatial_shape, k=self.k)
341 spatial_pad = SpatialPad(spatial_size=new_size, method=self.method)
342 return spatial_pad.compute_pad_width(spatial_shape)
343
344
345class Crop(InvertibleTransform, LazyTransform):

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…