如何把网站上线,惠州网站推广排名,网站建设评审意见,公司的网站建设公司python提供了PIL库和opencv库对图像进行读取并保存。
图像读入读出
给定一张RGB的彩色图像#xff0c;PIL库将其读入:
import cv2
from PIL import Image
# 读入图像
image2 Image.open(cub1.jpg)
print(type(image2))
image2_array np.array(image2)
print(image2_array…python提供了PIL库和opencv库对图像进行读取并保存。
图像读入读出
给定一张RGB的彩色图像PIL库将其读入:
import cv2
from PIL import Image
# 读入图像
image2 Image.open(cub1.jpg)
print(type(image2))
image2_array np.array(image2)
print(image2_array.shape)
print(image2_array.dtype)
# 保存图像
image_pil Image.fromarray(np.uint8(image2_array))
image_pil.save(pil.png)输出
class PIL.JpegImagePlugin.JpegImageFile
(224, 224, 3) # 3通道分别是RGB
uint8给定一张RGB的彩色图像OpenCV库将其读入:
import numpy as np
import cv2
# 读入图像
image1 cv2.imread(cub1.jpg)
print(type(image1))
print(image1.shape)
print(image1.dtype)
# 保存图像
cv2.imwrite(cv.png, np.uint8(image1))输出
class numpy.ndarray
(224, 224, 3) # 3通道分别是BGR
uint8