3
3
#include < QImage>
4
4
#include < QLabel>
5
5
6
- // http://stackoverflow.com/a/25878225/176769
7
- // http://mycodelog.com/2010/05/16/interpolation/
8
- #if 0
9
- QImage smooth_color_transition(const QImage& input, const QVector<QColor>& color_vec)
6
+ /*
7
+ * ColorMaps:
8
+ * http://jdherman.github.io/colormap/
9
+ * http://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/35242/versions/2/screenshot.jpg
10
+ * http://www.r-bloggers.com/gmt-standard-color-palettes/
11
+ *
12
+ * Linear interpolation:
13
+ * http://stackoverflow.com/a/25878225/176769
14
+ * http://mycodelog.com/2010/05/16/interpolation/
15
+ */
16
+
17
+ // Artificial colorization of an image based in 2 starting colors
18
+ QImage smooth_color_transition (const QImage& input, const QColor color_src, const QColor color_dst)
10
19
{
11
20
QImage output (input.size (), input.format ());
12
21
13
- QColor color_src = color_vec.at(0);
14
22
unsigned int r1 = color_src.red ();
15
23
unsigned int g1 = color_src.green ();
16
24
unsigned int b1 = color_src.blue ();
17
25
18
- QColor color_dst = color_vec.at(1);
19
26
unsigned int r2 = color_dst.red ();
20
27
unsigned int g2 = color_dst.green ();
21
28
unsigned int b2 = color_dst.blue ();
@@ -38,21 +45,20 @@ QImage smooth_color_transition(const QImage& input, const QVector<QColor>& color
38
45
39
46
return output;
40
47
}
41
- #endif
42
-
43
48
49
+ // Artificial colorization of an image based on color palette (vector)
44
50
QImage smooth_color_transition (const QImage& input, const QVector<QColor>& color_vec)
45
51
{
46
52
if (color_vec.size () < 2 )
47
53
return QImage ();
48
54
49
- QImage output (input.size (), input. format () );
55
+ QImage output (input.size (), QImage::Format_RGB888 );
50
56
51
57
int num_colors = color_vec.size ();
52
- std::cout << " Num colors:" << color_vec.size () << std::endl;
58
+ // std::cout << "Num colors:" << color_vec.size() << std::endl;
53
59
54
60
int color_width = 256 / (color_vec.size ()-1 );
55
- std::cout << " Color width:" << color_width << std::endl;
61
+ // std::cout << "Color width:" << color_width << std::endl;
56
62
57
63
QVector<QColor> pallete;
58
64
for (int c = 1 ; c < num_colors; c++)
@@ -72,10 +78,9 @@ QImage smooth_color_transition(const QImage& input, const QVector<QColor>& color
72
78
float p = i / (float )color_width; // percentage
73
79
74
80
// Resultant Color = RGB(A*(1-P)+X*P, B*(1-P)+Y*P, C*(1-P)+Z*P)
75
-
76
81
int r = (int ) r1 * (1 -p) + r2 * p;
77
82
int g = (int ) g1 * (1 -p) + g2 * p;
78
- int b = (int ) b1 * (1 -p) + b2 * p;
83
+ int b = (int ) b1 * (1 -p) + b2 * p;
79
84
pallete.push_back (qRgb (r, g, b));
80
85
}
81
86
}
@@ -84,7 +89,7 @@ QImage smooth_color_transition(const QImage& input, const QVector<QColor>& color
84
89
for (int i = pallete.size (); i < 256 ; i++)
85
90
pallete.push_back (color_vec[color_vec.size ()-1 ].rgb ());
86
91
87
- std::cout << " Pallete size:" << pallete.size () << std::endl;
92
+ // std::cout << "Pallete size:" << pallete.size() << std::endl;
88
93
89
94
for (int x = 0 ; x < input.width (); x++)
90
95
{
@@ -106,37 +111,131 @@ int main(int argc, char* argv[])
106
111
107
112
QImage input (" /Users/karlphillip/workspace/GraphicsProgramming/qtSmoothColorTransition/heightmap.jpg" );
108
113
if (input.isNull ())
114
+ {
115
+ std::cout << " !!! Unable to load image" << std::endl;
109
116
return -1 ;
117
+ }
110
118
111
119
QLabel input_label;
112
120
input_label.setPixmap (QPixmap::fromImage (input));
113
121
input_label.resize (input.width (), input.height ());
114
122
input_label.show ();
115
123
116
124
QVector<QColor> colors;
117
- colors.push_back (QColor (0 , 120 , 200 )); // dark blue
118
- colors.push_back (QColor (120 , 220 , 255 )); // cyan
119
- colors.push_back (QColor (71 , 141 , 104 )); // dark green
120
- colors.push_back (QColor (106 , 168 , 107 )); // medium green
121
- colors.push_back (QColor (141 , 173 , 132 )); // light green
122
- colors.push_back (QColor (166 , 191 , 151 )); // super light green
123
- colors.push_back (QColor (217 , 233 , 188 )); // sand yellow
124
- colors.push_back (QColor (185 , 140 , 90 )); // light orange
125
- colors.push_back (QColor (162 , 90 , 34 )); // light red
126
- colors.push_back (QColor (144 , 61 , 45 )); // dark red
127
- colors.push_back (QColor (151 , 68 , 64 )); // super dark red
128
- colors.push_back (QColor (156 , 146 , 170 )); // purple-red
129
- colors.push_back (QColor (170 , 170 , 210 )); // purple-white
130
- colors.push_back (QColor (240 , 247 , 243 )); // white
131
125
126
+ // Terrain
127
+ colors.push_back (QColor (1 , 1 , 48 )); // dark blue
128
+ colors.push_back (QColor (29 , 24 , 245 )); // blue
129
+ colors.push_back (QColor (0 , 255 , 254 )); // cyan
130
+ colors.push_back (QColor (0 , 100 , 56 )); // dark green
131
+ colors.push_back (QColor (0 , 127 , 63 )); // green-1
132
+ colors.push_back (QColor (3 , 153 , 72 )); // green-2
133
+ colors.push_back (QColor (54 , 178 , 86 )); // green-3
134
+ colors.push_back (QColor (116 , 204 , 119 )); // light green
135
+ colors.push_back (QColor (173 , 229 , 161 )); // light green-2
136
+ colors.push_back (QColor (227 , 255 , 209 )); // sand
137
+ colors.push_back (QColor (186 , 192 , 107 )); // dark sand
138
+ colors.push_back (QColor (184 , 90 , 35 )); // dark orange
139
+ colors.push_back (QColor (105 , 42 , 0 )); // dark red
140
+ // colors.push_back(QColor(245, 245, 250)); // snow
141
+
142
+ /*
143
+ // jet
144
+ colors.push_back(QColor(0, 0, 191));
145
+ colors.push_back(QColor(0, 0, 255));
146
+ colors.push_back(QColor(0, 64, 255));
147
+ colors.push_back(QColor(0, 128, 255));
148
+ colors.push_back(QColor(0, 191, 255));
149
+ colors.push_back(QColor(0, 255, 255));
150
+ colors.push_back(QColor(64, 255, 191));
151
+ colors.push_back(QColor(128, 255, 128));
152
+ colors.push_back(QColor(64, 255, 191));
153
+ colors.push_back(QColor(191, 255, 64));
154
+ colors.push_back(QColor(255, 255, 0));
155
+ colors.push_back(QColor(255, 191, 0));
156
+ colors.push_back(QColor(255, 191, 0));
157
+ colors.push_back(QColor(255, 128, 0));
158
+ colors.push_back(QColor(255, 64, 0));
159
+ colors.push_back(QColor(255, 0, 0));
160
+ colors.push_back(QColor(191, 0, 0));
161
+ colors.push_back(QColor(128, 64, 0));
162
+ */
163
+
164
+ /*
165
+ // BGR
166
+ colors.push_back(QColor(0, 0, 255));
167
+ colors.push_back(QColor(0, 255, 0));
168
+ colors.push_back(QColor(255, 0, 0));
169
+ */
170
+
171
+ /*
172
+ // hot
173
+ colors.push_back(QColor(43, 0, 0));
174
+ colors.push_back(QColor(85, 0, 0));
175
+ colors.push_back(QColor(128, 0, 0));
176
+ colors.push_back(QColor(170, 0, 0));
177
+ colors.push_back(QColor(213, 0, 0));
178
+ colors.push_back(QColor(255, 0, 0));
179
+ colors.push_back(QColor(255, 43, 0));
180
+ colors.push_back(QColor(255, 85, 0));
181
+ colors.push_back(QColor(255, 128, 0));
182
+ colors.push_back(QColor(255, 170, 0));
183
+ colors.push_back(QColor(255, 213, 0));
184
+ colors.push_back(QColor(255, 255, 0));
185
+ colors.push_back(QColor(255, 255, 64));
186
+ colors.push_back(QColor(255, 255, 128));
187
+ colors.push_back(QColor(255, 255, 191));
188
+ colors.push_back(QColor(255, 255, 255));
189
+ */
190
+
191
+ /*
192
+ // cool
193
+ colors.push_back(QColor(0, 255, 255));
194
+ colors.push_back(QColor(17, 238, 255));
195
+ colors.push_back(QColor(34, 221, 255));
196
+ colors.push_back(QColor(51, 204, 255));
197
+ colors.push_back(QColor(68, 187, 255));
198
+ colors.push_back(QColor(85, 170, 255));
199
+ colors.push_back(QColor(102, 153, 255));
200
+ colors.push_back(QColor(68, 187, 255));
201
+ colors.push_back(QColor(85, 170, 255));
202
+ colors.push_back(QColor(102, 153, 255));
203
+ colors.push_back(QColor(119, 136, 255));
204
+ colors.push_back(QColor(136, 119, 255));
205
+ colors.push_back(QColor(153, 102, 255));
206
+ colors.push_back(QColor(170, 85, 255));
207
+ colors.push_back(QColor(187, 68, 255));
208
+ colors.push_back(QColor(204, 51, 255));
209
+ colors.push_back(QColor(221, 34, 255));
210
+ colors.push_back(QColor(238, 17, 255));
211
+ colors.push_back(QColor(255, 0, 255));
212
+ */
213
+
214
+ /*
215
+ // water temperature
216
+ colors.push_back(QColor(41, 10, 216));
217
+ colors.push_back(QColor(38, 77, 255));
218
+ colors.push_back(QColor(63, 160, 255));
219
+ colors.push_back(QColor(114, 217, 255));
220
+ colors.push_back(QColor(140, 247, 255));
221
+ colors.push_back(QColor(224, 255, 255));
222
+ colors.push_back(QColor(255, 255, 191));
223
+ colors.push_back(QColor(255, 224, 153));
224
+ colors.push_back(QColor(255, 255, 191));
225
+ colors.push_back(QColor(255, 173, 114));
226
+ colors.push_back(QColor(247, 109, 94));
227
+ colors.push_back(QColor(216, 38, 50));
228
+ colors.push_back(QColor(164, 0, 33));
229
+ */
230
+
231
+ // Build colored elevation map
132
232
QImage output = smooth_color_transition (input, colors);
233
+ output.save (" /Users/karlphillip/workspace/GraphicsProgramming/qtSmoothColorTransition/output.jpg" );
133
234
134
235
QLabel output_label;
135
236
output_label.setPixmap (QPixmap::fromImage (output));
136
237
output_label.resize (output.width (), output.height ());
137
238
output_label.show ();
138
239
139
- output.save (" colored.jpg" );
140
-
141
240
return app.exec ();
142
241
}
0 commit comments