wolffd@0
|
1 function color = som_normcolor(data, clrmap)
|
wolffd@0
|
2
|
wolffd@0
|
3 %SOM_NORMCOLOR RGB values of indexed colors for a given dataset and colormap
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % color = som_normcolor(data, [clrmap])
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % color = som_normcolor(data);
|
wolffd@0
|
8 % color = som_normcolor(data,jet(64));
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % Input and output arguments ([]'s are optional):
|
wolffd@0
|
11 % data (struct) map or data struct
|
wolffd@0
|
12 % (matrix) size N x dim
|
wolffd@0
|
13 % [clrmap] (matrix) size N x 3, a valid colormap (an RGB value matrix)
|
wolffd@0
|
14 % Default is current colormap. See COLORMAP.
|
wolffd@0
|
15 %
|
wolffd@0
|
16 % color (matrix) size N x 3 x dim, RGB matrix
|
wolffd@0
|
17 %
|
wolffd@0
|
18 % Purpose of this function is to calculate fixed RGB colors that are similar
|
wolffd@0
|
19 % to indexed colors with the specified colormap. This is because some
|
wolffd@0
|
20 % SOM Toolbox visualization functions (as SOM_GRID) do not use indexed colors
|
wolffd@0
|
21 % if the underlying Matlab function (e.g. PLOT) do not use indexed colors
|
wolffd@0
|
22 %
|
wolffd@0
|
23 % EXAMPLE
|
wolffd@0
|
24 %
|
wolffd@0
|
25 % %%% Visualize three variables in a map using som_grid:
|
wolffd@0
|
26 % %%% Give coordinates for the markers according to variables 1 and 2, and
|
wolffd@0
|
27 % %%% 'indexed colors' according to variable 3.
|
wolffd@0
|
28 %
|
wolffd@0
|
29 % som_grid(map.topol.lattice,map.topol.msize,'Coord',map.codebook(:,1:2), ...
|
wolffd@0
|
30 % 'markercolor', som_normcolor(map.codebook(:,3)));
|
wolffd@0
|
31
|
wolffd@0
|
32 % Contributed to SOM Toolbox 2.0, February 11th, 2000 by Johan Himberg
|
wolffd@0
|
33 % Copyright (c) by Johan Himberg
|
wolffd@0
|
34 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
35
|
wolffd@0
|
36 % juha 150799 johan 010999
|
wolffd@0
|
37
|
wolffd@0
|
38 %%%% check possible errors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
39
|
wolffd@0
|
40 error(nargchk(1,2,nargin));
|
wolffd@0
|
41
|
wolffd@0
|
42 if nargin < 2| isempty(clrmap),
|
wolffd@0
|
43 clrmap=colormap;
|
wolffd@0
|
44 elseif ~vis_valuetype(clrmap,{'nx3rgb'}),
|
wolffd@0
|
45 error('The specified colormap is invalid!');
|
wolffd@0
|
46 end
|
wolffd@0
|
47
|
wolffd@0
|
48 d=size(clrmap,1);
|
wolffd@0
|
49
|
wolffd@0
|
50 if isstruct(data),
|
wolffd@0
|
51 m_names={'type';'codebook';'topol';'labels';'neigh';'mask';'trainhist';...
|
wolffd@0
|
52 'name';'comp_names';'comp_norm'};
|
wolffd@0
|
53 d_names=fieldnames(vis_struct);
|
wolffd@0
|
54 if length(fieldnames(data)) ~= length(d_names) % data is not som_data_struct
|
wolffd@0
|
55 if length(fieldnames(data)) ~= length(m_names) % and not som_map_struct
|
wolffd@0
|
56 error('Input argument is not a ''som_vis'' or ''som_map'' struct.')
|
wolffd@0
|
57 elseif ~all(strcmp(fieldnames(data),m_names))
|
wolffd@0
|
58 error('Input argument is not a ''som_vis'' or ''som_map'' struct.')
|
wolffd@0
|
59 else
|
wolffd@0
|
60 data=data.codebook;
|
wolffd@0
|
61 end
|
wolffd@0
|
62 elseif ~all(strcmp(fieldnames(data),dnames))
|
wolffd@0
|
63 error('Input argument is not a ''som_vis'' or ''som_map'' struct.')
|
wolffd@0
|
64 else
|
wolffd@0
|
65 data=data.data;
|
wolffd@0
|
66 end
|
wolffd@0
|
67 end
|
wolffd@0
|
68
|
wolffd@0
|
69 if ~isnumeric(data) | ndims(data) ~= 2
|
wolffd@0
|
70 error('Data is not 2 dimensional numeric matrix.');
|
wolffd@0
|
71 end
|
wolffd@0
|
72
|
wolffd@0
|
73 %%% action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
74
|
wolffd@0
|
75 data=som_normalize(data,'range');
|
wolffd@0
|
76
|
wolffd@0
|
77 for i=1:size(data,2),
|
wolffd@0
|
78 inds=~isnan(data(:,i));
|
wolffd@0
|
79 color(inds,:,i)=clrmap(round(data(inds,i)*(d-1))+1,:);
|
wolffd@0
|
80 color(~inds,:,i)=NaN;
|
wolffd@0
|
81 end
|
wolffd@0
|
82
|
wolffd@0
|
83
|
wolffd@0
|
84
|
wolffd@0
|
85
|
wolffd@0
|
86
|
wolffd@0
|
87
|
wolffd@0
|
88
|
wolffd@0
|
89
|