center_crop center_crop ( img, output_size ) [source]

Crops the given Image and resize it to desired size.

  • img (PIL.Image|np.array) – Image to be cropped. (0,0) denotes the top left corner of the image.

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


Cropped image.

Return type

PIL.Image or np.array

Examples: .. code-block:: python

import numpy as np from PIL import Image from import functional as F

fake_img = (np.random.rand(256, 300, 3) * 255.).astype(‘uint8’)

fake_img = Image.fromarray(fake_img)

cropped_img = F.center_crop(fake_img, (150, 100)) print(cropped_img.size)