8位深度转换为24位深度
import os
import numpy as np
import PIL
from PIL import Image
import cv2
path = "png_512/test/img"
for file in os.listdir(path):
filename = os.path.join(path,file)
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(f'png_512_24/test/img/{file}', imgs)
24位深度转换为8位深度
import os
import numpy as np
import PIL
from PIL import Image
import cv2
path = "png_256_(0-255)_24_8/val/labelcol"
for file in os.listdir(path):
filename = os.path.join(path,file)
img = cv2.imread(filename)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite(f'png_256_(0-255)_24_8/val/label/{file}', img)