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

Class BorderPadd

monai/transforms/croppad/dictionary.py:228–277  ·  view source on GitHub ↗

Pad the input data by adding specified borders to every dimension. Dictionary-based wrapper of :py:class:`monai.transforms.BorderPad`. This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic ` for more information.

Source from the content-addressed store, hash-verified

226
227
228class BorderPadd(Padd):
229 """
230 Pad the input data by adding specified borders to every dimension.
231 Dictionary-based wrapper of :py:class:`monai.transforms.BorderPad`.
232
233 This transform is capable of lazy execution. See the :ref:`Lazy Resampling topic<lazy_resampling>`
234 for more information.
235 """
236
237 backend = BorderPad.backend
238
239 def __init__(
240 self,
241 keys: KeysCollection,
242 spatial_border: Sequence[int] | int,
243 mode: SequenceStr = PytorchPadMode.CONSTANT,
244 allow_missing_keys: bool = False,
245 lazy: bool = False,
246 **kwargs,
247 ) -> None:
248 """
249 Args:
250 keys: keys of the corresponding items to be transformed.
251 See also: :py:class:`monai.transforms.compose.MapTransform`
252 spatial_border: specified size for every spatial border. it can be 3 shapes:
253
254 - single int number, pad all the borders with the same size.
255 - length equals the length of image shape, pad every spatial dimension separately.
256 for example, image shape(CHW) is [1, 4, 4], spatial_border is [2, 1],
257 pad every border of H dim with 2, pad every border of W dim with 1, result shape is [1, 8, 6].
258 - length equals 2 x (length of image shape), pad every border of every dimension separately.
259 for example, image shape(CHW) is [1, 4, 4], spatial_border is [1, 2, 3, 4], pad top of H dim with 1,
260 pad bottom of H dim with 2, pad left of W dim with 3, pad right of W dim with 4.
261 the result shape is [1, 7, 11].
262
263 mode: available modes for numpy array:{``"constant"``, ``"edge"``, ``"linear_ramp"``, ``"maximum"``,
264 ``"mean"``, ``"median"``, ``"minimum"``, ``"reflect"``, ``"symmetric"``, ``"wrap"``, ``"empty"``}
265 available modes for PyTorch Tensor: {``"constant"``, ``"reflect"``, ``"replicate"``, ``"circular"``}.
266 One of the listed string values or a user supplied function. Defaults to ``"constant"``.
267 See also: https://numpy.org/doc/1.18/reference/generated/numpy.pad.html
268 https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html
269 It also can be a sequence of string, each element corresponds to a key in ``keys``.
270 allow_missing_keys: don&#x27;t raise exception if key is missing.
271 lazy: a flag to indicate whether this transform should execute lazily or not. Defaults to False.
272 kwargs: other arguments for the `np.pad` or `torch.pad` function.
273 note that `np.pad` treats channel dimension as the first dimension.
274
275 """
276 padder = BorderPad(spatial_border=spatial_border, lazy=lazy, **kwargs)
277 Padd.__init__(self, keys, padder=padder, mode=mode, allow_missing_keys=allow_missing_keys, lazy=lazy)
278
279
280class DivisiblePadd(Padd):

Callers 3

test_transformsMethod · 0.90
test_inverse.pyFile · 0.90

Calls

no outgoing calls

Tested by 2

test_transformsMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…