cropping pictures before data loading in python code example

Example 1: crop image python

from PIL import Image # import pillow library (can install with "pip install pillow")
im = Image.open('card.png')
im = im.crop( (1, 0, 826, 1125) ) # previously, image was 826 pixels wide, cropping to 825 pixels wide
im.save('card.png') # saves the image
# im.show() # opens the image

Example 2: how to cut image python

im = Image.open('0.png').convert('L')
im = im.crop((1, 1, 98, 33))
im.save('_0.png')

Example 3: crop image python

import cv2
img = cv2.imread("lenna.png")
crop_img = img[y:y+h, x:x+w]
cv2.imshow("cropped", crop_img)
cv2.waitKey(0)