comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_normcolor.m @ 0:e9a9cd732c1e tip

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