opencv, PIL, skimage 三种读图

opencv, PIL, skimage 三种读图

import skimage
import cv2
import numpy as np
from PIL import Image
path = "/CT/data/test/original_images/0000001895_IMG-0010-00012.png"

#### PIL.Image
image = Image.open(path)
image.save("Image.png") # RGB
image = image.convert("L") # 单通道二值图像
image = np.expand_dims(image, axis=2)
image = np.concatenate((image, image, image), axis=-1)
cv2.imwrite("Image_gray.png", image) # 三通道 二值图像

### CV
img = cv2.imread(path) # GBR IMAGE
img = cv2.imread(path, cv2.IMREAD_GRAYSCALE) # 灰度图像
print(img.shape) # (W, H, C) # GBR t图像
cv2.imwrite("cv1.png", img)
image = np.zeros([img.shape[0], img.shape[1], img.shape[2]], dtype=img.dtype)
image[:, :, 0] = img[:, :, 2]
image[:, :, 1] = img[:, :, 1]
image[:, :, 2] = img[:, :, 0]
cv2.imwrite("cv_rgb.png", image) # GBR转RGB

#### skimage
image = skimage.io.imread(path) # RGB
image = skimage.color.rgb2gray(image) # 灰度图像
skimage.io.imsave("skimage.png", image)

你可能感兴趣的:(学习记录,计算机视觉)