← Back to all transforms
CenterCrop
Description
Crop the central part of the input. This transform crops the center of the input image, mask, bounding boxes, and keypoints to the specified dimensions. It's useful when you want to focus on the central region of the input, discarding peripheral information. Args: height (int): The height of the crop. Must be greater than 0. width (int): The width of the crop. Must be greater than 0. pad_if_needed (bool): Whether to pad if crop size exceeds image size. Default: False. pad_mode (OpenCV flag): OpenCV border mode used for padding. Default: cv2.BORDER_CONSTANT. pad_cval (number | tuple[number, number] | list[number]): Padding value for images if border_mode is cv2.BORDER_CONSTANT. Default: 0. pad_cval_mask (number | tuple[number, number] | list[number]): Padding value for masks if border_mode is cv2.BORDER_CONSTANT. Default: 0. pad_position (str): Position of padding ('center', 'top_left', 'top_right', 'bottom_left', 'bottom_right', 'random'). Default: 'center'. p (float): Probability of applying the transform. Default: 1.0. Targets: image, mask, bboxes, keypoints Image types: uint8, float32 Note: - If pad_if_needed is False and crop size exceeds image dimensions, it will raise a CropSizeError. - If pad_if_needed is True and crop size exceeds image dimensions, the image will be padded. - For bounding boxes and keypoints, coordinates are adjusted appropriately for both padding and cropping.
Parameters
- height: int (default: 320)
- width: int (default: 320)
- pad_if_needed: bool (default: false)
- pad_mode: Literal['cv2.BORDER_CONSTANT', 'cv2.BORDER_REPLICATE', 'cv2.BORDER_REFLECT', 'cv2.BORDER_WRAP', 'cv2.BORDER_DEFAULT', 'cv2.BORDER_TRANSPARENT'] (default: 0)
- pad_cval: int | float | tuple[int | float, int | float] | list[int | float] (default: 0)
- pad_cval_mask: int | float | tuple[int | float, int | float] | list[int | float] (default: 0)
- pad_position: Literal['center', 'top_left', 'top_right', 'bottom_left', 'bottom_right', 'random'] (default: 'center')
- p: float (default: 1)
Targets
- Image
- Mask
- BBoxes
- Keypoints
Try it out
ⓘ