图像单通道转三通道
作者:互联网
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import torchvision.transforms as transforms
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
image=Image.open('00000.jpg').convert('L')
print(image.size)
plt.subplot(1,2,1)
plt.title("origin")
plt.imshow(image)
image = np.array(image)
print(image.shape)
image = np.expand_dims(image,axis=2)
print(image.shape)
image = np.concatenate((image, image, image), axis=-1)
print(image.shape)
image = Image.fromarray(image.astype('uint8')).convert('L')
print(image.size)
plt.subplot(1, 2, 2)
plt.title("change")
plt.imshow(image)
plt.show()
标签:plt,image,转三,np,图像,print,import,Image,单通道 来源: https://blog.csdn.net/weixin_44311020/article/details/121888186