Open bobvo23 opened 3 years ago
For those who the upper code doesn't work. `from PIL import Image
import cv2 import numpy import glob import sys import numpy as np import os np.set_printoptions(threshold=sys.maxsize)
path = '/Users/bogus/Downloads/SegmentationClass/' # Source Folder dstpath = '/Users/bogus/Downloads/SegmentationClass2/' # Destination Folder
VOC_COLORMAP = [[176, 112, 32], [48, 240, 32], [48, 112, 32], [176, 240, 160], [176, 240, 32], [48, 240, 160], [176, 112, 160]]
VOC_CLASSES = ['background', 'hyperthalamus', 'cerebral', 'thalamus', 'hippo', 'soma', 'audi']
def convert_to_iii(file_dir): """Build an RGB color to label mapping for segmentation.""" im=cv2.imread(file_dir) print("im",im[1,1]) for i, colormap in enumerate(VOC_COLORMAP):
im[np.where((im == [colormap[2],colormap[1],colormap[0]]).all(axis = 2))] = [i,i,i]
filename = os.path.split(file_dir)[-1]
cv2.imwrite((os.path.join(dstpath,filename)),im)
def voc_label_indices(folder_dir): explore_path = folder_dir + "/*.png" path_list = glob.glob(explore_path) print(explore_path) print("len",len(path_list)) for file_dir in path_list: print(file_dir) convert_to_iii(file_dir)
copy_bool = input("Copy target directory before excute. Excute? (Y/N):")
if copy_bool=='y' or copy_bool=='Y': print("Start conversion") voc_label_indices(path) print("Done") else : print("See you") `
Hi, this repository extracts the Blue pixel value to indicate the corresponding class of the pixel. However, the VOC dataset uses a combination of RGB to indicate the correspond class. I'm trying to convert the VOC Segmentation label to this style using the following code. Do we have any other option?