import cv2 import numpy as np try: from PIL import Image except ImportError: import Image img_file = '/home/test_crop.jpg' im = Image.open(img_file).convert('L') im = im.crop((55, 563, 1603, 975)) im.save('_0defects.jpg')