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

Method compute_pad_width

monai/transforms/croppad/array.py:221–237  ·  view source on GitHub ↗

dynamically compute the pad width according to the spatial shape. Args: spatial_shape: spatial shape of the original image.

(self, spatial_shape: Sequence[int])

Source from the content-addressed store, hash-verified

219 super().__init__(mode=mode, lazy=lazy, **kwargs)
220
221 def compute_pad_width(self, spatial_shape: Sequence[int]) -> tuple[tuple[int, int]]:
222 """
223 dynamically compute the pad width according to the spatial shape.
224
225 Args:
226 spatial_shape: spatial shape of the original image.
227
228 """
229 spatial_size = fall_back_tuple(self.spatial_size, spatial_shape)
230 if self.method == Method.SYMMETRIC:
231 pad_width = []
232 for i, sp_i in enumerate(spatial_size):
233 width = max(sp_i - spatial_shape[i], 0)
234 pad_width.append((int(width // 2), int(width - (width // 2))))
235 else:
236 pad_width = [(0, int(max(sp_i - spatial_shape[i], 0))) for i, sp_i in enumerate(spatial_size)]
237 return tuple([(0, 0)] + pad_width) # type: ignore
238
239
240class BorderPad(Pad):

Callers 1

compute_pad_widthMethod · 0.95

Calls 3

fall_back_tupleFunction · 0.90
maxFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected