-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreateColorMap.m
More file actions
235 lines (225 loc) · 6.72 KB
/
CreateColorMap.m
File metadata and controls
235 lines (225 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
function [red, grn, blu] = CreateColorMap(ColorMap, NumColors)
%CREATECOLORMAP Creates a colormap
% [red,grn,blu] = CREATECOLORMAP(ColorMap) takes a ColorMap name (string)
% and returns float arrays of red, green and blue colors (0-1) that
% compose the map. ColorMap can be one of the following:
%
% 'Feature Type'
% 'Feature Type QA'
% 'Ice/Water Phase'
% 'Ice/Water Phase QA'
% 'Aerosol Sub-Type'
% 'Cloud Sub-Type'
% 'PSC Sub-Type'
% 'Sub-Type'
% 'Sub-Type QA'
% 'Averaging Required for Detection'
%
% These correspond to ClassText.FieldDescription returned by
% vfm_type(), and have a fixed number of colors to match exactly the
% colors used on the CALIPSO website to show these feature flags.
%
% [red,grn,blu] = CREATECOLORMAP(ColorMap, NumColors) works the same
% way, but allows one to choose the number of colors. In this case,
% only generic linear colormaps are available, which are named:
%
% 'Rainbow' or 'default'
% 'BlackWhite'
% 'BlackGold'
%
% History:
% 2021-mar-09 Added names for all colormaps associated with standard
% feature flags. NumColors is now the 2nd parameter, and
% only used for linear colormaps. Colors now match those
% used on the CALIPSO website.
%
% 2005-mar-28 Original code by Ralph Kuehn shared on CALIPO's
% website, from 2005/03/28.
%
if strcmp(ColorMap,'Feature Type')
red = [255 0 0 255 250 0 192 0]'/255;
grn = [255 38 220 160 255 255 192 0]'/255;
blu = [255 255 255 0 0 110 192 0]'/255;
return;
end
if strcmp(ColorMap,'Feature Type QA')
red = [ 230 0 230 255 0 255]'/255;
grn = [ 230 0 0 255 200 0]'/255;
blu = [ 230 0 0 0 0 255]'/255;
return;
end
if strcmp(ColorMap,'Ice/Water Phase')
red = [ 192 255 255 0 169]'/255;
grn = [ 255 0 255 0 169]'/255;
blu = [ 168 0 255 255 169]'/255;
return;
end
if strcmp(ColorMap,'Ice/Water Phase QA')
red = [ 192 255 255 0 169]'/255;
grn = [ 255 0 255 0 169]'/255;
blu = [ 168 0 255 255 169]'/255;
return;
end
if strcmp(ColorMap,'Aerosol Sub-Type')
red = [ 198 0 250 255 0 174 0 255]'/255;
grn = [ 198 0 255 0 128 87 0 0]'/255;
blu = [ 198 255 0 0 0 0 0 255]'/255;
return
end
if strcmp(ColorMap,'Cloud Sub-Type')
red = [ 0 0 0 144 255 255 192 255 255]'/255;
grn = [ 0 0 255 255 255 159 192 255 0]'/255;
blu = [ 0 144 255 111 0 0 192 255 255]'/255;
return
end
if strcmp(ColorMap,'PSC Sub-Type')
red = [255 0 0 144 255 255 192 255 255]'/255;
grn = [ 0 0 255 255 255 159 192 255 0]'/255;
blu = [ 0 144 255 111 0 0 192 255 255]'/255;
return;
end
if strcmp(ColorMap,'Sub-Type')
red = [255 0 0 144 255 255 192 255 255]'/255;
grn = [ 0 0 255 255 255 159 192 255 0]'/255;
blu = [ 0 144 255 111 0 0 192 255 255]'/255;
return;
end
if strcmp(ColorMap,'Sub-Type QA')
red = [ 0 180 255]'/255;
grn = [ 0 180 255]'/255;
blu = [ 0 180 255]'/255;
return;
end
if strcmp(ColorMap,'Averaging Required for Detection')
red = [ 202 244 0 255 0 0]'/255;
grn = [ 202 104 255 255 125 0]'/255;
blu = [ 255 12 0 0 63 128]'/255;
return;
end
if nargin == 1
disp('Received only 1 argument, but 2 are required for linear colormaps.')
red = [ nan ]
grn = [ nan ]
blu = [ nan ]
return
end
if (strcmp(ColorMap,'Rainbow') | strcmp(ColorMap,'default'))
fprintf('Using Rainbow colormap\n');
start_hsv(1) = 300;
final_hsv(1) = 15;
start_hsv(2) = 1000;
final_hsv(2) = 1000;
start_hsv(3) = 1000;
final_hsv(3) = 1000;
elseif strcmp(ColorMap,'BlackWhite')
fprintf('Using Black and White colormap\n');
start_hsv(1) = 0;
final_hsv(1) = 0;
start_hsv(2) = 0;
final_hsv(2) = 0;
start_hsv(3) = 1000;
final_hsv(3) = 0;
elseif strcmp(ColorMap,'BlackGold')
fprintf('Using Black and Gold colormap\n');
start_hsv(1) = 59;
final_hsv(1) = 39;
start_hsv(2) = 1000;
final_hsv(2) = 730;
start_hsv(3) = 0;
final_hsv(3) = 1000;
else
disp(['Unknown ColorMap. Check input', ColorMap]);
return
end
Dhue = (final_hsv(1) - start_hsv(1))/NumColors;
Dsat = (final_hsv(2) - start_hsv(2))/NumColors;
Dval = (final_hsv(3) - start_hsv(3))/NumColors;
hue = start_hsv(1);
sat = start_hsv(2);
val = start_hsv(3);
if (strcmp(ColorMap,'Rainbow') | strcmp(ColorMap,'default')),
R = zeros(NumColors,1);
G = zeros(NumColors,1);
B = zeros(NumColors,1);
bluStep = 4;
grnStep = 3.2;
i = 1;
while (hue >= final_hsv(1)),
[R(i),G(i),B(i)]=HSVtoRGB(round(hue),round(sat),round(val));
% ColorValue(i)=red*65536+grn*256+blu;
if (hue <= 254) && (hue >= 222),
hue = hue + Dhue*bluStep;
elseif (hue <= 140) && (hue >= 85),
hue = hue + Dhue*grnStep;
else
hue = hue + Dhue;
end
i = i + 1;
end
% Copy color info to new array of correct size
red = ones(i,1).*R(1:i);
grn = ones(i,1).*G(1:i);
blu = ones(i,1).*B(1:i);
else
red = zeros(NumColors,1);
grn = zeros(NumColors,1);
blu = zeros(NumColors,1);
for i=1:NumColors,
[red(i),grn(i),blu(i)]=HSVtoRGB(round(hue),round(sat),round(val));
% ColorValue(i)=red*65536+grn*256+blu;
hue = hue + Dhue;
sat = sat + Dsat;
val = val + Dval;
if (hue < 0.0), hue = hue + 360; end
if (hue > 360.0), hue = hue - 360; end
% Should use a better convention below because
% there would be a discontinuity in the colormap
% if we jump from ~0 to ~1000.
if (sat < 0.0), sat = sat + 1000; end
if (sat > 1000) sat = sat - 1000; end
if (val < 0.0) val = val + 1000; end
if (val > 1000.0) val = val + 1000; end
end
end
red(1) = 0;
grn(1) = 0;
blu(1) = 0;
red(i) = 1;
grn(i) = 1;
blu(i) = 1;
function [r,g,b] = HSVtoRGB( h, s, v)
% int i, f;
% int p, q, t;
% s = (s * 0xff) / 1000;
% v = (v * 0xff) / 1000;
ff = 255;
s = (s * ff) / 1000;
v = (v * ff) / 1000;
if (h == 360), h = 0; end
if (s == 0), h = 0; r = v; g = v; b = v; end
i = floor(h / 60);
f = mod(h,60);
% p = v * (0xff - s) / 0xff;
% q = v * (0xff - s * f / 60) / 0xff;
% t = v * (0xff - s * (60 - f) / 60) / 0xff;
p = v * (ff - s) / ff;
q = v * (ff - s * f / 60) / ff;
t = v * (ff - s * (60 - f) / 60) / ff;
if i == 0,
r = v; g = t; b = p;
elseif i == 1,
r = q; g = v; b = p;
elseif i == 2,
r = p; g = v; b = t;
elseif i == 3,
r = p; g = q; b = v;
elseif i == 4,
r = t; g = p; b = v;
elseif i == 5,
r = v; g = p; b = q;
else,
r = ff; g = ff; b = ff;
end
r = r/ff;
g = g/ff;
b = b/ff;