转变:
1、Image.open 》》 cv2.imread
img = Image.open(path)
re_img = np.asarray(img)
2、cv2.imread 》》 Image.open
Image.fromarray(np.uint8(re_img))
1、图片读取
1-1、Image.open
img = Image.open(pic_path)
img = Image.open(BytesIO(content))
print(type(img))
print(img)
img.show()
'''
<class 'PIL.JpegImagePlugin.JpegImageFile'>
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=100x30 at 0x269ACC79430>
'''
1-2、cv2.imread
tp_img = cv2.imread('bb.png')
print(type(tp_img))
print(tp_img)
'''
<class 'numpy.ndarray'>
[[[106 122 88]
[ 0 15 0]
[100 131 94]
...
[106 126 91]
[106 126 91]
[106 126 91]]
'''
2、灰度化
3、创建一个图像
'''
mode(模式) bands(通道) 说明
“1” 1 数字1,表示黑白二值图片,每个像素用0或1共1位二进制码表示
“L” 1 灰度图
“P” 1 索引图
“RGB” 3 24位真彩图
“RGBA” 4 “RGB”+透明通道
“CMYK” 4 印刷模式图像
'''
im = Image.new('RGB', (100, 100), 'green')
im.show("CMYK")
4、图像混合
4-1、透明度混合
from PIL import Image
im1 = Image.open('pic.jpg').convert(mode='RGB')
im2 = Image.new('RGB', im1.size, 'red')
Image.blend(im1, im2, 0.5).show()