import os
import shutil
import cv2
import numpy as np
src = "./Dataset/mask/"
dst = "./Dataset/gray_mask/"
if os.path.exists(dst):
print('Output directory already exists: ', dst)
shutil.rmtree(dst)
os.makedirs(dst)
for p in os.listdir(src):
mask_path = os.path.join(src, p)
print(mask_path)
mask = cv2.imread(mask_path)
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
mask = np.array(mask)
mask[mask == 0] = 129
mask[mask == 38.0] = 0
mask[mask == 75.0] = 255
mask[mask == 113.0] = 192
mask[mask == 15.0] = 64
cv2.imwrite(os.path.join(dst, p), mask)
labelme彩色mask转gray mask
最新推荐文章于 2024-05-23 09:47:00 发布