# VOC Segmentation GT图像颜色表生成分析

PASCAL VOC图像分割数据集中，图像中各个类别以不同的颜色进行区分，即Ground Truth中，每种颜色都对应着相应的类别：

% VOCLABELCOLORMAP Creates a label color map such that adjacent indices have different
% colors.  Useful for reading and writing index images which contain large indices,
% by encoding them as RGB images.
%
% CMAP = VOCLABELCOLORMAP(N) creates a label color map with N entries.
function cmap = labelcolormap(N)

if nargin==0
N=256
end
cmap = zeros(N,3);
for i=1:N
id = i-1; r=0;g=0;b=0;
for j=0:7
r = bitor(r, bitshift(bitget(id,1),7 - j));
g = bitor(g, bitshift(bitget(id,2),7 - j));
b = bitor(b, bitshift(bitget(id,3),7 - j));
id = bitshift(id,-3);
end
cmap(i,1)=r; cmap(i,2)=g; cmap(i,3)=b;
end
cmap = cmap / 255;

     0     0     0
128     0     0
0   128     0
128   128     0
0     0   128
128     0   128
0   128   128
128   128   128
64     0     0
192     0     0
64   128     0
192   128     0
64     0   128
192     0   128
64   128   128
192   128   128
0    64     0
128    64     0
0   192     0
128   192     0
0    64   128

0 (0,0,0)
1 (128,0,0)
2 (0,128,0)
3 (128,128,0)
4 (0,0,128)
5 (128,0,128)
6 (0,128,128)
7 (128,128,128)
8 (64,0,0)
9 (192,0,0)
10 (64,128,0)
11 (192,128,0)
12 (64,0,128)
13 (192,0,128)
14 (64,128,128)
15 (192,128,128)
16 (0,64,0)
17 (128,64,0)
18 (0,192,0)
19 (128,192,0)
20 (0,64,128)

def uint82bin(n, count=8):
"""returns the binary of integer n, count refers to amount of bits"""
return ''.join([str((n >> y) & 1) for y in range(count-1, -1, -1)])

def labelcolormap(N):
cmap = np.zeros((N, 3), dtype = np.uint8)
for i in range(N):
r = 0
g = 0
b = 0
id = i
for j in range(7):
str_id = uint82bin(id)
r = r ^ ( np.uint8(str_id[-1]) << (7-j))
g = g ^ ( np.uint8(str_id[-2]) << (7-j))
b = b ^ ( np.uint8(str_id[-3]) << (7-j))
id = id >> 3
cmap[i, 0] = r
cmap[i, 1] = g
cmap[i, 2] = b
return cmap

[[  0   0   0]
[128   0   0]
[  0 128   0]
[128 128   0]
[  0   0 128]
[128   0 128]
[  0 128 128]
[128 128 128]
[ 64   0   0]
[192   0   0]
[ 64 128   0]
[192 128   0]
[ 64   0 128]
[192   0 128]
[ 64 128 128]
[192 128 128]
[  0  64   0]
[128  64   0]
[  0 192   0]
[128 192   0]
[  0  64 128]]

• 本文已收录于以下专栏：

举报原因： 您举报文章：VOC Segmentation GT图像颜色表生成分析 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)