赞
踩
5种方式:
1、调用opencv库
import cv2
image_path = “绝对路径”
image = cv2.imread(image_path)
cv2.imshow(“cv2_image”, image)
cv2.waitKey()
2、PIL方式(Python Image Library)
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
image_path=“绝对路径”
img=Image.open(image_path)
img=np.array(img)
plt.imshow(img)
plt.show()
3、matplotlib.image
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
image_path=“绝对路径”
img=mpimg.imread(image_path)
plt.imshow(img)
plt.show()
4、skimage.io
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
image_path=“绝对路径”
img=io.imread(image_path)
plt.imshow(img)
plt.show()
5、scipy.misc
from scipy.misc import imread, imshow, imsave
import matplotlib.pyplot as plt
image_path=“绝对路径”
img=io.imread(image_path)
plt.imshow(img)
plt.show()
imsave(“路径”, img)
统一使用plt进行显示,不管是plt还是cv2.imshow,在python中只认numpy.array,但是由于cv2.imread的图片是BGR,cv2.imshow时相应的换通道显示
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。