Resize `img` by cropping or expanding the image from the center. The `resize_dims` values are the output dimensions (or None to use original dimension of `img`). If a dimension is smaller than that of `img` then the result will be cropped and if larger padded with zeros, in both cases t
(img: np.ndarray, *resize_dims: int | None, fill_value: float = 0.0, inplace: bool = True)
| 338 | |
| 339 | |
| 340 | def resize_center(img: np.ndarray, *resize_dims: int | None, fill_value: float = 0.0, inplace: bool = True): |
| 341 | """ |
| 342 | Resize `img` by cropping or expanding the image from the center. The `resize_dims` values are the output dimensions |
| 343 | (or None to use original dimension of `img`). If a dimension is smaller than that of `img` then the result will be |
| 344 | cropped and if larger padded with zeros, in both cases this is done relative to the center of `img`. The result is |
| 345 | a new image with the specified dimensions and values from `img` copied into its center. |
| 346 | """ |
| 347 | |
| 348 | resize_dims = fall_back_tuple(resize_dims, img.shape) |
| 349 | |
| 350 | half_img_shape = (np.asarray(img.shape) // 2).tolist() |
| 351 | half_dest_shape = (np.asarray(resize_dims) // 2).tolist() |
| 352 | srcslices, destslices = copypaste_arrays(img.shape, resize_dims, half_img_shape, half_dest_shape, resize_dims) |
| 353 | |
| 354 | if not inplace: |
| 355 | dest = np.full(resize_dims, fill_value, img.dtype) # type: ignore |
| 356 | dest[destslices] = img[srcslices] |
| 357 | return dest |
| 358 | return img[srcslices] |
| 359 | |
| 360 | |
| 361 | def check_non_lazy_pending_ops( |
nothing calls this directly
no test coverage detected
searching dependent graphs…