1im = Image.open('image.jpg')
2im = im.crop((left, top, width, height))
3
4# ├─input image width─┤
5# ┬ ┌───────────────────┐ ┬ ┬
6# │ │ │top │
7# input │ ┌───────┐ │ ┴ height
8# image │ │ │ │ │
9# height│ └───────┘ │ ┴
10# │ │ │
11# ┴ └───────────────────┘
12# ├─left─┤
13# ├─────width─────┤
1im = Image.open('image.jpg')
2im = im.crop((left, top, right, bottom)) # coordinates of the crop
1im = Image.open('0.png').convert('L')
2im = im.crop((1, 1, 98, 33))
3im.save('_0.png')
1import cv2
2img = cv2.imread("lenna.png")
3crop_img = img[y:y+h, x:x+w]
4cv2.imshow("cropped", crop_img)
5cv2.waitKey(0)