Shortcuts

center_crop

torchvision.transforms.functional.center_crop(img: Tensor, output_size: List[int]) Tensor[source]

Crops the given image at the center. 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 center cropped.

Parameters:
  • img (PIL Image or Tensor) – Image to be cropped.

  • output_size (sequence or int) – (height, width) of the crop box. If int or sequence with single int, it is used for both directions.

Returns:

Cropped image.

Return type:

PIL Image or Tensor

Examples using center_crop:

Illustration of transforms

Illustration of transforms

Illustration of transforms

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