当前位置 : 主页 > 手机开发 > ROM >

matplotlib常见操作

来源:互联网 收集:自由互联 发布时间:2021-06-10
import os import numpy as np from PIL import Image import matplotlib.pyplot as plt img = Image.open(os.path.join(‘images‘, ‘cat‘ + ‘.jpg‘)) gray = img.convert(‘L‘) r,g,b = img.split() img_merged = Image.merge(‘RGB‘, (r,

import os
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt

img = Image.open(os.path.join(‘images‘, ‘cat‘ + ‘.jpg‘))
gray = img.convert(‘L‘)
r,g,b = img.split()
img_merged = Image.merge(‘RGB‘, (r, g, b))


plt.figure(figsize=(10,5)) #设置窗口大小
plt.suptitle(‘Multi_Image‘) # 图片名称
plt.subplot(2,3,1), plt.title(‘image‘)
plt.imshow(img), plt.axis(‘off‘)
plt.subplot(2,3,2), plt.title(‘gray‘)
plt.imshow(gray,cmap=‘gray‘), plt.axis(‘off‘) #这里显示灰度图要加cmap
plt.subplot(2,3,3), plt.title(‘img_merged‘)
plt.imshow(img_merged), plt.axis(‘off‘)
plt.subplot(2,3,4), plt.title(‘r‘)
plt.imshow(r,cmap=‘gray‘), plt.axis(‘off‘)
plt.subplot(2,3,5), plt.title(‘g‘)
plt.imshow(g,cmap=‘gray‘), plt.axis(‘off‘)
plt.subplot(2,3,6), plt.title(‘b‘)
plt.imshow(b,cmap=‘gray‘), plt.axis(‘off‘)

plt.show()

网友评论