COLORMAP_JET的颜色规律
程序员文章站
2022-03-27 08:58:10
...
关于applyColorMap
函数的使用参考:
1. COLORMAP_JET简介
计算机视觉中最常用的颜色映射算法是Jet,它具有高的对比度可以有效突出图像中的细节。但如果仔细观察图像的梯度图会发现一系列的颜色带,在青色和黄色区域最为明显。
缺点:这对于伪彩图最大的影响在于颜色变化过于剧烈,将导致人眼对于实际数据的误解。很多平滑过渡的区域会被误解为有较大的梯度。由于Jet映射对于人眼感知来说变化不是常量,所以它不具有感知均匀性。这种影响对于色盲人士来说更为明显,将造成伪彩图映射出的信息变得模糊。
2. 灰度到JET的映射
2.1 灰度值映射成JET
对于0~255范围的灰度值映射成JET模式的伪彩,对照情况如下:
将其对应的值打印出来:
Mat img = Mat(20, 256, CV_8UC1);
for (size_t i = 0; i < 20; i++)
{
uchar* p = img.ptr<uchar>(i);
for (int j = 0; j < 256; j++) {
p[j] = j;
}
}
imshow("color", img);
Mat jet;
applyColorMap(img, jet, COLORMAP_JET);
imshow("jet", jet);
for (size_t i = 0; i < 1; i++)
{
uchar* p0 = img.ptr<uchar>(i);
/*uchar* p1 = imgRGB[0].ptr<uchar>(i);
uchar* p2= imgRGB[1].ptr<uchar>(i);
uchar* p3 = imgRGB[2].ptr<uchar>(i);*/
Vec3b* p = jet.ptr<Vec3b>(i);
for (size_t j = 0; j < 256; j++)
{
cout << (int)p0[j]<<" —— "<< "BGR(" << int(p[j][0]) << "," << int(p[j][1]) << "," << int(p[j][2]) << ")" << endl;
}
}
waitKey();
输出的对照值:
0 —— BGR(128,0,0)
1 —— BGR(132,0,0)
2 —— BGR(136,0,0)
3 —— BGR(140,0,0)
4 —— BGR(144,0,0)
5 —— BGR(148,0,0)
6 —— BGR(152,0,0)
7 —— BGR(156,0,0)
8 —— BGR(160,0,0)
9 —— BGR(164,0,0)
10 —— BGR(168,0,0)
11 —— BGR(172,0,0)
12 —— BGR(176,0,0)
13 —— BGR(180,0,0)
14 —— BGR(184,0,0)
15 —— BGR(188,0,0)
16 —— BGR(192,0,0)
17 —— BGR(196,0,0)
18 —— BGR(200,0,0)
19 —— BGR(204,0,0)
20 —— BGR(208,0,0)
21 —— BGR(212,0,0)
22 —— BGR(216,0,0)
23 —— BGR(220,0,0)
24 —— BGR(224,0,0)
25 —— BGR(228,0,0)
26 —— BGR(232,0,0)
27 —— BGR(236,0,0)
28 —— BGR(240,0,0)
29 —— BGR(244,0,0)
30 —— BGR(248,0,0)
31 —— BGR(252,0,0)
32 —— BGR(255,0,0)
33 —— BGR(255,4,0)
34 —— BGR(255,8,0)
35 —— BGR(255,12,0)
36 —— BGR(255,16,0)
37 —— BGR(255,20,0)
38 —— BGR(255,24,0)
39 —— BGR(255,28,0)
40 —— BGR(255,32,0)
41 —— BGR(255,36,0)
42 —— BGR(255,40,0)
43 —— BGR(255,44,0)
44 —— BGR(255,48,0)
45 —— BGR(255,52,0)
46 —— BGR(255,56,0)
47 —— BGR(255,60,0)
48 —— BGR(255,64,0)
49 —— BGR(255,68,0)
50 —— BGR(255,72,0)
51 —— BGR(255,76,0)
52 —— BGR(255,80,0)
53 —— BGR(255,84,0)
54 —— BGR(255,88,0)
55 —— BGR(255,92,0)
56 —— BGR(255,96,0)
57 —— BGR(255,100,0)
58 —— BGR(255,104,0)
59 —— BGR(255,108,0)
60 —— BGR(255,112,0)
61 —— BGR(255,116,0)
62 —— BGR(255,120,0)
63 —— BGR(255,124,0)
64 —— BGR(255,128,0)
65 —— BGR(255,132,0)
66 —— BGR(255,136,0)
67 —— BGR(255,140,0)
68 —— BGR(255,144,0)
69 —— BGR(255,148,0)
70 —— BGR(255,152,0)
71 —— BGR(255,156,0)
72 —— BGR(255,160,0)
73 —— BGR(255,164,0)
74 —— BGR(255,168,0)
75 —— BGR(255,172,0)
76 —— BGR(255,176,0)
77 —— BGR(255,180,0)
78 —— BGR(255,184,0)
79 —— BGR(255,188,0)
80 —— BGR(255,192,0)
81 —— BGR(255,196,0)
82 —— BGR(255,200,0)
83 —— BGR(255,204,0)
84 —— BGR(255,208,0)
85 —— BGR(255,212,0)
86 —— BGR(255,216,0)
87 —— BGR(255,220,0)
88 —— BGR(255,224,0)
89 —— BGR(255,228,0)
90 —— BGR(255,232,0)
91 —— BGR(255,236,0)
92 —— BGR(255,240,0)
93 —— BGR(255,244,0)
94 —— BGR(255,248,0)
95 —— BGR(255,252,0)
96 —— BGR(254,255,2)
97 —— BGR(250,255,6)
98 —— BGR(246,255,10)
99 —— BGR(242,255,14)
100 —— BGR(238,255,18)
101 —— BGR(234,255,22)
102 —— BGR(230,255,26)
103 —— BGR(226,255,30)
104 —— BGR(222,255,34)
105 —— BGR(218,255,38)
106 —— BGR(214,255,42)
107 —— BGR(210,255,46)
108 —— BGR(206,255,50)
109 —— BGR(202,255,54)
110 —— BGR(198,255,58)
111 —— BGR(194,255,62)
112 —— BGR(190,255,66)
113 —— BGR(186,255,70)
114 —— BGR(182,255,74)
115 —— BGR(178,255,78)
116 —— BGR(174,255,82)
117 —— BGR(170,255,86)
118 —— BGR(166,255,90)
119 —— BGR(162,255,94)
120 —— BGR(158,255,98)
121 —— BGR(154,255,102)
122 —— BGR(150,255,106)
123 —— BGR(146,255,110)
124 —— BGR(142,255,114)
125 —— BGR(138,255,118)
126 —— BGR(134,255,122)
127 —— BGR(130,255,126)
128 —— BGR(126,255,130)
129 —— BGR(122,255,134)
130 —— BGR(118,255,138)
131 —— BGR(114,255,142)
132 —— BGR(110,255,146)
133 —— BGR(106,255,150)
134 —— BGR(102,255,154)
135 —— BGR(98,255,158)
136 —— BGR(94,255,162)
137 —— BGR(90,255,166)
138 —— BGR(86,255,170)
139 —— BGR(82,255,174)
140 —— BGR(78,255,178)
141 —— BGR(74,255,182)
142 —— BGR(70,255,186)
143 —— BGR(66,255,190)
144 —— BGR(62,255,194)
145 —— BGR(58,255,198)
146 —— BGR(54,255,202)
147 —— BGR(50,255,206)
148 —— BGR(46,255,210)
149 —— BGR(42,255,214)
150 —— BGR(38,255,218)
151 —— BGR(34,255,222)
152 —— BGR(30,255,226)
153 —— BGR(26,255,230)
154 —— BGR(22,255,234)
155 —— BGR(18,255,238)
156 —— BGR(14,255,242)
157 —— BGR(10,255,246)
158 —— BGR(6,255,250)
159 —— BGR(1,255,254)
160 —— BGR(0,252,255)
161 —— BGR(0,248,255)
162 —— BGR(0,244,255)
163 —— BGR(0,240,255)
164 —— BGR(0,236,255)
165 —— BGR(0,232,255)
166 —— BGR(0,228,255)
167 —— BGR(0,224,255)
168 —— BGR(0,220,255)
169 —— BGR(0,216,255)
170 —— BGR(0,212,255)
171 —— BGR(0,208,255)
172 —— BGR(0,204,255)
173 —— BGR(0,200,255)
174 —— BGR(0,196,255)
175 —— BGR(0,192,255)
176 —— BGR(0,188,255)
177 —— BGR(0,184,255)
178 —— BGR(0,180,255)
179 —— BGR(0,176,255)
180 —— BGR(0,172,255)
181 —— BGR(0,168,255)
182 —— BGR(0,164,255)
183 —— BGR(0,160,255)
184 —— BGR(0,156,255)
185 —— BGR(0,152,255)
186 —— BGR(0,148,255)
187 —— BGR(0,144,255)
188 —— BGR(0,140,255)
189 —— BGR(0,136,255)
190 —— BGR(0,132,255)
191 —— BGR(0,128,255)
192 —— BGR(0,124,255)
193 —— BGR(0,120,255)
194 —— BGR(0,116,255)
195 —— BGR(0,112,255)
196 —— BGR(0,108,255)
197 —— BGR(0,104,255)
198 —— BGR(0,100,255)
199 —— BGR(0,96,255)
200 —— BGR(0,92,255)
201 —— BGR(0,88,255)
202 —— BGR(0,84,255)
203 —— BGR(0,80,255)
204 —— BGR(0,76,255)
205 —— BGR(0,72,255)
206 —— BGR(0,68,255)
207 —— BGR(0,64,255)
208 —— BGR(0,60,255)
209 —— BGR(0,56,255)
210 —— BGR(0,52,255)
211 —— BGR(0,48,255)
212 —— BGR(0,44,255)
213 —— BGR(0,40,255)
214 —— BGR(0,36,255)
215 —— BGR(0,32,255)
216 —— BGR(0,28,255)
217 —— BGR(0,24,255)
218 —— BGR(0,20,255)
219 —— BGR(0,16,255)
220 —— BGR(0,12,255)
221 —— BGR(0,8,255)
222 —— BGR(0,4,255)
223 —— BGR(0,0,255)
224 —— BGR(0,0,252)
225 —— BGR(0,0,248)
226 —— BGR(0,0,244)
227 —— BGR(0,0,240)
228 —— BGR(0,0,236)
229 —— BGR(0,0,232)
230 —— BGR(0,0,228)
231 —— BGR(0,0,224)
232 —— BGR(0,0,220)
233 —— BGR(0,0,216)
234 —— BGR(0,0,212)
235 —— BGR(0,0,208)
236 —— BGR(0,0,204)
237 —— BGR(0,0,200)
238 —— BGR(0,0,196)
239 —— BGR(0,0,192)
240 —— BGR(0,0,188)
241 —— BGR(0,0,184)
242 —— BGR(0,0,180)
243 —— BGR(0,0,176)
244 —— BGR(0,0,172)
245 —— BGR(0,0,168)
246 —— BGR(0,0,164)
247 —— BGR(0,0,160)
248 —— BGR(0,0,156)
249 —— BGR(0,0,152)
250 —— BGR(0,0,148)
251 —— BGR(0,0,144)
252 —— BGR(0,0,140)
253 —— BGR(0,0,136)
254 —— BGR(0,0,132)
255 —— BGR(0,0,128)
2.2 JET映射规律
i从0开始取值。
灰度值 | B | G | R |
---|---|---|---|
0~31 | 128+4i | 0 | 0 |
32 | 255 | 0 | 0 |
33~95 | 255 | 4+4i | 0 |
96 | 254 | 255 | 2 |
97~158 | 250-4i | 255 | 6+4i |
159 | 1 | 255 | 254 |
160~223 | 0 | 252-4i | 255 |
224~255 | 0 | 0 | 252-4i |
2.3 c++实现Jet映射
Mat test=Mat(20,256,CV_8UC3);
int s;
for (int i = 0; i < 20; i++) {
Vec3b* p = test.ptr<Vec3b>(i);
for (s = 0; s < 32; s++) {
p[s][0] = 128 + 4 * s;
p[s][1] = 0;
p[s][2] = 0;
}
p[32][0] = 255;
p[32][1] = 0;
p[32][2] = 0;
for (s = 0; s < 63; s++) {
p[33+s][0] = 255;
p[33+s][1] = 4+4*s;
p[33+s][2] = 0;
}
p[96][0] = 254;
p[96][1] = 255;
p[96][2] = 2;
for (s = 0; s < 62; s++) {
p[97 + s][0] = 250 - 4 * s;
p[97 + s][1] = 255;
p[97 + s][2] = 6+4*s;
}
p[159][0] = 1;
p[159][1] = 255;
p[159][2] = 254;
for (s = 0; s < 64; s++) {
p[160 + s][0] = 0;
p[160 + s][1] = 252 - (s * 4);
p[160 + s][2] = 255;
}
for (s = 0; s < 32; s++) {
p[224 + s][0] = 0;
p[224 + s][1] = 0;
p[224 + s][2] = 252-4*s;
}
}
imshow("me", test);
waitKey();