Table of Contents
Shortcuts

# crop

torchvision.transforms.functional.crop(img: Tensor, top: int, left: int, height: int, width: int) → Tensor

  Crop the given image at specified location and output size. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions. If image size is smaller than output size along any edge, image is padded with 0 and then cropped.

  Parameters:

    - img (PIL Image or Tensor) – Image to be cropped. (0,0) denotes the top left corner of the image.

    - top (int) – Vertical component of the top left corner of the crop box.

    - left (int) – Horizontal component of the top left corner of the crop box.

    - height (int) – Height of the crop box.

    - width (int) – Width of the crop box.

  Returns:

    Cropped image.

  Return type:

    PIL Image or Tensor

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.