PIL 读取图像,显示图像,ROI,保存图像
import matplotlib.pyplot as plt
from PIL import Image
src_img = Image.open(Src_Image_Path)
print(src_img.size)
plt.figure("src_image")
plt.imshow(src_img)
plt.show()
L = src_img.convert('L')
L.show()
height, width = src_img.size[0], src_img.size[1]
center = [height//2, width//2]
print(center)
left, top = center[0] - 128//2, center[1] - 128//2
right, bottom = center[0] + 128//2, center[1] + 128//2
img_roi = src_img.crop(box=(left, top, right, bottom))
img_roi.show()
img_roi.save(Image_Path)