← Back to all transforms

RandomCrop

Description

Crop a random part of the input.

    Args:
        height: height of the crop.
        width: width of the crop.
        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: probability of applying the transform. Default: 1.

    Targets:
        image, mask, bboxes, keypoints

    Image types:
        uint8, float32

    Note:
        If pad_if_needed is True and crop size exceeds image dimensions, the image will be padded
        before applying the random crop.
    

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

Original Image:

Original Image: (733, 484, 3)

Original Image

Bbox Params

Keypoint Params

Mask: (733, 484, 3)

Mask

BBoxes: (733, 484, 3)

BBoxes

Keypoints: (733, 484, 3)

Keypoints