get rgv value from color name. [Usage] rgb_val = rgb_val_get(color_name) [Input] color_name : color name/namelist [string/cell string] These short/long name can be used as color name. 'y' : 'yellow' 'm' : 'magenta' 'c' : 'cyan' 'r' : 'red' 'g' : 'green' 'b' : 'blue' 'w' : 'white' 'k' : 'black' 'o' : 'orange' 'db' : 'darkbrown' 'nb' : 'navyblue' 'sb' : 'skyblue' 'lb' : 'lightblue' 'br' : 'brown' 'yg' : 'yellowgreen' 'bg' : 'bottlegreen' [Output] rgb_val : rgb value (R G B) [Nx3] The range of R/G/B is from 0 to 1. [Example] % get orange value rgb_val = rgb_val_get('o'); rgb_val = rgb_val_get('orange'); % get multiple rgb value rgb_vals = rgb_val_get({'y', 'm', 'c'}); Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function rgb_val = rgb_val_get(color_name) 0002 % get rgv value from color name. 0003 % 0004 % [Usage] 0005 % rgb_val = rgb_val_get(color_name) 0006 % 0007 % [Input] 0008 % color_name : color name/namelist [string/cell string] 0009 % These short/long name can be used as color name. 0010 % 'y' : 'yellow' 0011 % 'm' : 'magenta' 0012 % 'c' : 'cyan' 0013 % 'r' : 'red' 0014 % 'g' : 'green' 0015 % 'b' : 'blue' 0016 % 'w' : 'white' 0017 % 'k' : 'black' 0018 % 'o' : 'orange' 0019 % 'db' : 'darkbrown' 0020 % 'nb' : 'navyblue' 0021 % 'sb' : 'skyblue' 0022 % 'lb' : 'lightblue' 0023 % 'br' : 'brown' 0024 % 'yg' : 'yellowgreen' 0025 % 'bg' : 'bottlegreen' 0026 % 0027 % [Output] 0028 % rgb_val : rgb value (R G B) [Nx3] 0029 % The range of R/G/B is from 0 to 1. 0030 % 0031 % [Example] 0032 % % get orange value 0033 % rgb_val = rgb_val_get('o'); 0034 % rgb_val = rgb_val_get('orange'); 0035 % 0036 % % get multiple rgb value 0037 % rgb_vals = rgb_val_get({'y', 'm', 'c'}); 0038 % 0039 % Copyright (C) 2011, ATR All Rights Reserved. 0040 % License : New BSD License(see VBMEG_LICENSE.txt) 0041 0042 0043 % RGB value % color name 0044 rgb_table = { 0045 {[1 1 0], {'y', 'yellow'}}; 0046 {[1 0 1], {'m', 'magenta'}}; 0047 {[0 1 1], {'c', 'cyan'}}; 0048 {[1 0 0], {'r', 'red'}}; 0049 {[0 1 0], {'g', 'green'}}; 0050 {[0 0 1], {'b', 'blue'}}; 0051 {[1 1 1], {'w', 'white'}}; 0052 {[0 0 0], {'k', 'black'}}; 0053 {[1 0.648 0], {'o', 'orange'}}; 0054 {[0.435 0.294 0.243], {'db', 'darkbrown'}}; 0055 {[0 0 0.5], {'nb', 'navyblue'}}; 0056 {[0.529 0.808 0.922], {'sb', 'skyblue'}}; 0057 {[0.4 1 1], {'lb', 'lightblue'}}; 0058 {[0.647 0.165 0.165], {'br', 'brown'}}; 0059 {[0.604 0.804 0.196], {'yg', 'yellowgreen'}}; 0060 {[0.2 0.377 0.271], {'bg', 'bottlegreen'}}; 0061 }; 0062 0063 % 0064 % --- Previous check 0065 % 0066 if nargin ~= 1 0067 help(mfilename); 0068 return; 0069 end 0070 0071 % 0072 % --- Main Procedure 0073 % 0074 if ischar(color_name) 0075 color_name = {color_name}; 0076 end 0077 Ncolors = length(color_name); 0078 0079 rgb_val = []; 0080 for k=1:Ncolors 0081 rgb_val = [rgb_val; inner_find_color(rgb_table, color_name{k})]; 0082 end 0083 0084 function [rgb_value] = inner_find_color(rgb_table, color_name) 0085 % find rgb value by searching color table. 0086 % 0087 % [Input] 0088 % color_name : string 0089 % [Output] 0090 % rgb_value : [R G B] or empty(when not found). 0091 0092 rgb_value = []; 0093 0094 for k=1:length(rgb_table) 0095 color_name_def = rgb_table{k}{2}; 0096 ix = strmatch(lower(color_name), lower(color_name_def), 'exact'); 0097 if ~isempty(ix) 0098 rgb_value = rgb_table{k}{1}; 0099 break; 0100 end 0101 end 0102 if isempty(rgb_value) 0103 warning('The specified color : %s not found.', color_name); 0104 end