center_crop

paddle.vision.transforms. center_crop ( img, output_size ) [source]

Crops the given Image and resize it to desired size.

Parameters
  • 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

Returns

Cropped image.

Return type

PIL.Image or np.array

Examples

import numpy as np
from PIL import Image
from paddle.vision.transforms 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)