https://blog.csdn.net/column/details/pythonpil.html
示例:
from PIL import Image
import pytesseract pytesseract.pytesseract.tesseract_cmd = r'D:\Program Files\Tesseract-OCR\tesseract.exe'
im = Image.open(r'a.jpg')
print(im)
print(im.mode)
print(im.getpixel((,))) gray = im.convert('L')
gray.save('ag.jpg')
print(gray)
print(gray.mode)
print(gray.getpixel((,)))
# 所有比阈值亮的像素转换为白色,所有比阈值暗的像素转换为黑色
# 灰度 白色为255,黑色为0
b = gray.point(lambda x: if x< else ,'')
b.save('b.jpg')
输出:
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=500x291 at 0x16328A31438>
RGB
(, , )
<PIL.Image.Image image mode=L size=500x291 at 0x16328A313C8>
L
a.jpg
ag.jpg
b.jpg