IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
classes2colormap.m
Go to the documentation of this file.
1 %>@ingroup graphicsapi conversion classlabelsgroup
2 %>@file
3 %>@brief Generates a colormap from an integer vector of classes.
4 %>
5 %> The vector may also have "refuses" and outlier indicators (-1, -2, -3, ...). These negative values will be marked as
6 %> black
7 %
8 %> @param y integer vector of classes
9 %> @param flag_skip Whether to skip the non-existent indexes. If FALSE, colormap will be filled with grays
10 %> @return cm
11 function cm = classes2colormap(y, flag_skip)
12 
13 if nargin < 2 || isempty(flag_skip)
14  flag_skip = 0;
15 end;
16 
17 u1 = unique(y(y < 0));
18 u2 = unique(y(y >= 0));
19 
20 n1 = numel(u1);
21 n2 = numel(u2);
22 
23 cm = zeros(0, 3);
24 i = 1;
25 for class = min(u1):-1
26  if sum(u1 == class) > 0
27  cm(i, :) = [1, 1, 1]*0;
28  i = i+1;
29  else
30  if ~flag_skip
31  cm(i, :) = [1, 1, 1]*.5;
32  i = i+1;
33  end;
34  end;
35 end;
36 
37 j = 1;
38 for class = 0:max(u2)
39  if sum(u2 == class) > 0
40  cm(i, :) = rgb(find_color(j));
41  i = i+1;
42  j = j+1;
43  else
44  if ~flag_skip
45  cm(i, :) = [1, 1, 1]*.5;
46  i = i+1;
47  end;
48  end;
49 end;
50 
function classes2colormap(in y, in flag_skip)
function find_color(in i)
Analysis Session (AS) base class.
Definition: as.m:6