import numpy as np
import cv2
import glob
import os
path = "E:\\Users\\CycleGAN-tf2.0-tourtial\\dataset\\PL\\crack\\testA\\*.jpg"
img_path = "E:\\Users\\CycleGAN-tf2.0-tourtial\\dataset\\PL\\"
for jpg_path in glob.glob(path):
img_name = os.path.basename(jpg_path)
img = cv2.imread(jpg_path,0)
img_rgb = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
img_paths = img_path+img_name
cv2.imwrite(img_paths, img_rgb)
修改相应路径即可使用。
方法二:使用PIL库。
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
import os
import sys
import shutil
path='E:\\Users\\CycleGAN-tf2.0-tourtial\\data