python如何保存图像_Python | 读取和保存图片的几种方式

分享使用 python 进行图像处理时,几种常见的图片读取和存储的方式。

Imagefrom PIL import Image

img = Image.open('img.jpg')

print(type(img)) #

print(img) #

img.show()

img.save('img_copy.jpg')

import numpy as np

img = np.array(img)

print(type(img)) #

print(img.shape) # (531, 742, 3)

skimagefrom skimage import io

img=io.imread('img.jpg')

print(type(img)) #

print(img.shape) # (531, 742, 3)

io.imshow(img)

io.show()

io.imsave('img_copy.jpg', img)

matplotlibimport matplotlib.pyplot as plt

img = plt.imread('img.jpg')

print(type(img)) #

print(img.shape) # (531, 742, 3)

plt.imshow(img)

plt.show()

plt.imsave('img_copy.jpg', img)

cv2import cv2

img = cv2.imread('img.jpg')

print(type(img)) #

print(img.shape) # (531, 742, 3)

cv2.imshow('image',img)

cv2.waitKey(0)

cv2.imwrite('img_copy.jpg', img)

scipyimport scipy.misc

img = scipy.misc.imread('img.jpg')

print(type(img)) #

print(img.shape) # (531, 742, 3)

from os import environ

environ['SCIPY_PIL_IMAGE_VIEWER'] = '' # 这里填 image viewer 路径

scipy.misc.imshow(img)

scipy.misc.imsave('img_copy.jpg', img)

你可能感兴趣的:(python如何保存图像)