Home > functions > common > utility > vb_get_class_color.m

vb_get_class_color

PURPOSE ^

Make color map for class label

SYNOPSIS ^

function cmap = vb_get_class_color(Nclass)

DESCRIPTION ^

 Make color map for class label
  cmap = vb_get_class_color(Nclass)
 --- Input
 Nclass : # of class
 --- Output
 cmap : colormap matrix for class plot
      : [Nclass x 3]

 2006-11-16 M.Sato

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    cmap = vb_get_class_color(Nclass)
0002 % Make color map for class label
0003 %  cmap = vb_get_class_color(Nclass)
0004 % --- Input
0005 % Nclass : # of class
0006 % --- Output
0007 % cmap : colormap matrix for class plot
0008 %      : [Nclass x 3]
0009 %
0010 % 2006-11-16 M.Sato
0011 %
0012 % Copyright (C) 2011, ATR All Rights Reserved.
0013 % License : New BSD License(see VBMEG_LICENSE.txt)
0014 
0015 if ~exist('Nclass','var'), Nclass = 64; end
0016 
0017 % Nclass = Nmap^3 : log(Nmap) = log(Nclass)/3 :
0018 
0019 Nmap   = ceil(exp(log(Nclass)/3));
0020 clevel = (0:Nmap)/Nmap;
0021 
0022 [c1, c2, c3] = ndgrid(clevel);
0023 
0024 cmap = [c1(:), c2(:), c3(:)];
0025 N    = size(cmap,1);
0026 cmap = cmap(2:(N-1),:);
0027 N    = N - 2;
0028 
0029 % load precalculated random permutation
0030 fname = 'rand_index.mat';
0031 
0032 if exist(fname,'file'), 
0033     load(fname,'rand_indx')
0034     %fprintf('Load index file\n')
0035     ix = rand_indx( rand_indx <= N );
0036 else
0037     ix   = randperm(N);
0038 end
0039 
0040 cmap = cmap(ix(1:Nclass),:);
0041 
0042 return
0043 %% --- END --- %%
0044 % gray, hot, cool, bone, copper, pink, flag, prism,
0045 
0046 N = ceil(Nclass/Nmap);
0047 ncmap = zeros(N*Nmap,3);
0048 ix = 1:Nmap;
0049 
0050 %cadd = gray(N) + flag(N);
0051 cadd = gray(N);
0052 
0053 for n = 1:N
0054  tmap = cmap + repmat(cadd(n,:), [Nmap 1]); 
0055  ncmap(ix,:) = tmap/max(tmap(:));
0056  ix = ix + Nmap;
0057 end
0058 
0059 ncmap = ncmap(1:Nclass,:);

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005