Args: k: the target k for each spatial dimension. if `k` is negative or 0, the original size is preserved. if `k` is an int, the same `k` be applied to all the input spatial dimensions. mode: available modes for numpy array:{``"constan
(
self,
k: Sequence[int] | int,
mode: str = PytorchPadMode.CONSTANT,
method: str = Method.SYMMETRIC,
lazy: bool = False,
**kwargs,
)
| 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) |