1
+ /* *
2
+ * OpenCV Custom Colormap Example
3
+ *
4
+ * Copyright 2015 by Satya Mallick <[email protected] >
5
+ *
6
+ */
7
+
8
+
9
+ #include " opencv2/opencv.hpp"
10
+
11
+ using namespace cv ;
12
+ using namespace std ;
13
+
14
+ Mat applyCustomColorMap (Mat& im_gray)
15
+ {
16
+ unsigned char b[] = {255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,253 ,251 ,249 ,247 ,245 ,242 ,241 ,238 ,237 ,235 ,233 ,231 ,229 ,227 ,225 ,223 ,221 ,219 ,217 ,215 ,213 ,211 ,209 ,207 ,205 ,203 ,201 ,199 ,197 ,195 ,193 ,191 ,189 ,187 ,185 ,183 ,181 ,179 ,177 ,175 ,173 ,171 ,169 ,167 ,165 ,163 ,161 ,159 ,157 ,155 ,153 ,151 ,149 ,147 ,145 ,143 ,141 ,138 ,136 ,134 ,132 ,131 ,129 ,126 ,125 ,122 ,121 ,118 ,116 ,115 ,113 ,111 ,109 ,107 ,105 ,102 ,100 ,98 ,97 ,94 ,93 ,91 ,89 ,87 ,84 ,83 ,81 ,79 ,77 ,75 ,73 ,70 ,68 ,66 ,64 ,63 ,61 ,59 ,57 ,54 ,52 ,51 ,49 ,47 ,44 ,42 ,40 ,39 ,37 ,34 ,33 ,31 ,29 ,27 ,25 ,22 ,20 ,18 ,17 ,14 ,13 ,11 ,9 ,6 ,4 ,2 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 };
17
+
18
+
19
+ unsigned char g[] = { 255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,255 ,254 ,252 ,250 ,248 ,246 ,244 ,242 ,240 ,238 ,236 ,234 ,232 ,230 ,228 ,226 ,224 ,222 ,220 ,218 ,216 ,214 ,212 ,210 ,208 ,206 ,204 ,202 ,200 ,198 ,196 ,194 ,192 ,190 ,188 ,186 ,184 ,182 ,180 ,178 ,176 ,174 ,171 ,169 ,167 ,165 ,163 ,161 ,159 ,157 ,155 ,153 ,151 ,149 ,147 ,145 ,143 ,141 ,139 ,137 ,135 ,133 ,131 ,129 ,127 ,125 ,123 ,121 ,119 ,117 ,115 ,113 ,111 ,109 ,107 ,105 ,103 ,101 ,99 ,97 ,95 ,93 ,91 ,89 ,87 ,85 ,83 ,82 ,80 ,78 ,76 ,74 ,72 ,70 ,68 ,66 ,64 ,62 ,60 ,58 ,56 ,54 ,52 ,50 ,48 ,46 ,44 ,42 ,40 ,38 ,36 ,34 ,32 ,30 ,28 ,26 ,24 ,22 ,20 ,18 ,16 ,14 ,12 ,10 ,8 ,6 ,4 ,2 ,0 };
20
+
21
+
22
+ unsigned char r[] = {195,194,193,191,190,189,188,187,186,185,184,183,182,181,179,178,177,176,175,174,173,172,171,170,169,167,166,165,164,163,162,161,160,159,158,157,155,154,153,152,151,150,149,148,147,146,145,143,142,141,140,139,138,137,136,135,134,133,131,130,129,128,127,126,125,125,125,125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126};
23
+
24
+ Mat channels[] = {Mat (256 ,1 , CV_8U, b), Mat (256 ,1 , CV_8U, g), Mat (256 ,1 , CV_8U, r)};
25
+ Mat lut; // Create a lookup table
26
+ merge (channels, 3 , lut);
27
+
28
+ Mat im_color;
29
+ LUT (im_gray, lut, im_color);
30
+
31
+ return im_color;
32
+
33
+ }
34
+
35
+
36
+
37
+ int main ( int argc, char ** argv )
38
+ {
39
+ // Read 8-bit grayscale image
40
+ Mat im = imread (" pluto.jpg" , IMREAD_GRAYSCALE);
41
+ cvtColor (im.clone (), im, COLOR_GRAY2BGR);
42
+ Mat im_color = applyCustomColorMap (im);
43
+
44
+ imshow (" Pseudo Colored Image" , im_color);
45
+ waitKey (0 );
46
+
47
+ }
0 commit comments