crop

paddle.vision.transforms. crop ( img, top, left, height, width ) [source]

Crops the given Image.

Parameters
  • img (PIL.Image|np.array) – 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 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.crop(fake_img, 56, 150, 200, 100)
print(cropped_img.size)