dynamically compute the pad width according to the spatial shape. Args: spatial_shape: spatial shape of the original image.
(self, spatial_shape: Sequence[int])
| 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 | |
| 240 | class BorderPad(Pad): |
no test coverage detected