本系列文章由 @yhl_leo 出品,转载请注明出处。

文章链接: http://blog.csdn.net/yhl_leo/article/details/52185581


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

可以看出这个颜色表既好看又容易区分开。下面来看,这个color map是如何产生的。

先附上Matlab版本的代码:

% 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;

其中,N就是类别数,而bitor()bitshift()bitget()这些位运算的函数,可以在Matlab中查询其功能,很容易理解(源码就不做分析了)。

对于VOC 20类的分割问题,我们调用:labelcolormap(21),可以得到如下输出(这里把结果乘以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)

我将Matlab代码转为python版本:

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

这里,我并没有将cmap保存成float型,而是无符号整型,不过这是小事。执行labelcolormap(21)后,得到输出如下:

[[  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]]

与Matlab版本的结果一致。

VOC Segmentation GT图像颜色表生成分析的更多相关文章

  1. [C#]生成预定义全颜色表

    生成Color类所有static预定义成员的颜色表 const long CELLS_PER_LINE = 10; const float MARGIN = 12; const float CELL_ ...

  2. GeoTiff如何存储颜色表的研究

    作者:朱金灿 来源:http://blog.csdn.net/clever101 在一次偶然的机会中得知tiff图像时可以存诸颜色表的,心想以后用GeoTiff来保存图像分类图像就十分方便了.于是研究 ...

  3. AMAP-TECH算法大赛开赛!基于车载视频图像的动态路况分析

    阿里巴巴高德地图AMAP-TECH算法大赛于7月8日开启初赛,赛题为「基于车载视频图像的动态路况分析」,活动邀请了业界权威专家担任评委,优秀选手不仅可以瓜分丰厚的奖金,领取荣誉证书,还有机会进入高德地 ...

  4. HTML & CSS & JavaScript 从一个表格到一个灰阶颜色表 03

    工具1:HBuilder X 1.9.9.20190522 工具2:火狐浏览器 67.0.4 (64 位) 其实,我还想使用表格,做一个这样的颜色表,如下图所示: 如果按照之前的做法,把每一种颜色都列 ...

  5. PS 颜色表大全-CMYK颜色表(2)

    CMYK颜色表 编号 C M Y K R G B 16进制值 1 0 100 100 45 139 0 22 8B0016 2 0 100 100 25 178 0 31 B2001F 3 0 100 ...

  6. linux性能监控分析及通过nmon_analyse生成分析报表

    nmon是一款分析 AIX 和 Linux 性能的免费工具 nmon 工具还可以将相同的数据捕获到一个文本文件,便于以后对报告进行分析和绘制图形.输出文件采用电子表格的格式 (.csv). 性能介绍 ...

  7. HTML RGB 颜色表 16进制表 颜色对应表

    HTML RGB 颜色表 16进制表 颜色对应表  16 常用颜色表(颜色 + RGB + 名字): Color Value Name   Color Value Name   #00FFFF aqu ...

  8. RGB与HSV之间的转换公式及颜色表

    RGB & HSV 英文全称 RGB - Red, Green, Blue HSV - Hue, Saturation, Value HSV --> RGB 转换公式 HSV --> ...

  9. Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应

    杂家前文Android颜色对照表只有颜色和十六进制,有时候需要设置r g b分量的int值,如paint.setARGB(255, 127, 255, 212);就需要自己计算下分量的各个值.这里提供 ...

随机推荐

  1. BS3 多级菜单

    <div class="container"> <div class="row"> <h2>Multi level drop ...

  2. drupal中文安装指导

    (注:drupal6中文包放在profiles/default/translations下,drupal7放在profiles/standard/translations下) Drupal 6 中文安 ...

  3. jQuery的基本使用及选择器和筛选器

    回顾 事件 鼠标clickdblclickcontextmenumouseentermouseleavemousemovemousedownmouseup​键盘keydownkeyupkeypress ...

  4. CF1066B Heaters

    思路: 从左向右贪心选择能覆盖当前位置的最靠右的那个heater即可,和poj radar installation类似. 实现: #include <iostream> #include ...

  5. 关于Retrofit + RxJava 的使用

    年前一个月到现在,一直都在忙一个项目.项目使用的三方框架还是蛮多的. 下面来总结一下自己使用Retrofit + RxJava的知识点吧. (以下讲述从一个请求的最初开始) 1.首先定义一个RxMan ...

  6. ef导航属性

    https://msdn.microsoft.com/en-us/data/jj574232.aspx  场景是   A表中有B,B表中又C.都是一堆多的关系.怎样Mapping是个问题啊.  var ...

  7. org.springframework.beans.factory.BeanCreationException: Could not autowire

    由于我在项目中引用了如下代码,增加了 @Configurationpublic class Connection {    public @Bean HttpClientConfig httpClie ...

  8. Could not load OpenSSL解决

    问题 Could not load OpenSSL. You must recompile Ruby with OpenSSL support or change the sources in you ...

  9. mac重启privoxy命令

    重启命令 brew services restart privoxy

  10. UVA 427 The Tower of Babylon 巴比伦塔(dp)

    据说是DAG的dp,可用spfa来做,松弛操作改成变长.注意状态的表示. 影响决策的只有顶部的尺寸,因为尺寸可能很大,所以用立方体的编号和高的编号来表示,然后向尺寸更小的转移就行了. #include ...