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

Function resize_center

monai/transforms/utils.py:340–358  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

338
339
340def 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
361def check_non_lazy_pending_ops(

Callers

nothing calls this directly

Calls 2

fall_back_tupleFunction · 0.90
copypaste_arraysFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…