Reputation: 983
I am doing image segmentation on PASCAL VOC 2012 dataset. I have 21 classes including background generated from the segmentation model. The shape of the segmentation output is (224,224,21) where each (224 * 224) is the feature map of each of 21 classes. Each of these maps contains indexes (1st map contains values in the array 1 only when that pixel belongs to the class 1 otherwise it is void and soon for other classes). Now I want to convert these index values in each map (0,1,2,..20) to their corresponding (R,G,B) values and store it as an image. (PASCAL VOC has a corresponding (R,G,B) value defined for each index value). I have absolutely no clue on how to achieve this. Any help is highly appreciated.
I have some questions on color mapping on SO and in other blogs using PASCAL VOC dataset but I couldn't understand them.
Upvotes: 2
Views: 1523
Reputation: 23556
If you want to use this data for the visualization, you may convert is like this:
RGB_colors = [(12,12,12), (13,13,13), ... 21 color for 21 classes ...]
image = np.zeros( (224,224,3) ) # black RGB image
for i in range(image.shape[0]) :
for j in range(image.shape[1]) :
color_index = output[i,j].index(1) # index of '1' value
image[i,j] = RGB_colors[ color_index ]
Upvotes: 2