title: python读入图片的四种方式
date: 2022-07-02 15:11:58
tags: image process
python读入图片的四种方式
'''
多种读入图片并显示,保存的方法总结
'''
def read_image1(filename):
'''
python自带的读入图片的方法
PIL
'''
from PIL import Image
import numpy as np
image = Image.open(filename)
image_array = np.array(image)
image.show()
image.save('./PIL1.png')
def read_image2(filename):
'''
opencv读入图片
opencv
'''
import cv2
image = cv2.imread(filename)
cv2.imshow('image', image)
key = cv2.waitKey(0)
if key == ord('q') or key==27:
print('hello')
cv2.imwrite('cv2.png', image)
def read_image3(filename):
'''
matplotlib.image
'''
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
image = mpimg.imread(filename)
plt.figure(num=1)
plt.imshow(image)
plt.savefig('plt.png')
plt.show()
def read_image4(filenmae):
'''
skimage
'''
from skimage import io
image = io.imread(filename)
io.imshow(image)
io.imsave('skimage1.png', image)
io.show()
if __name__ == '__main__':
filename = '../3_axes.png'
read_image4(filename)