原程序来源于网络,仅供参考学习,略有改动。
import os
import numpy as np
import PIL
from PIL import Image
import cv2
path = "../Data/errors/"
for root, dirs, files in os.walk(path):
for name in files:
print("files:",os.path.join(root,name))
filename = os.path.join(root,name)
img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
img_shape = img.shape
imgs = np.zeros(shape=(img_shape[0], img_shape[1], 3), dtype=np.float32)
imgs[:, :, 0] = img[:, :]
imgs[:, :, 1] = img[:, :]
imgs[:, :, 2] = img[:, :]
cv2.imwrite(filename, imgs)