Home > FMAToolbox > Plot > Bright.m

Bright

PURPOSE ^

Bright - Bright colormap (similar to HSV or JET, but brighter).

SYNOPSIS ^

function m = Bright(n,varargin)

DESCRIPTION ^

Bright - Bright colormap (similar to HSV or JET, but brighter).

  USAGE

    m = Bright(n,<options>)

    n              optional number of rows in output matrix (default = 100)
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'hgamma'      gamma-like correction for hue (1 = no correction, default)
     'type'        either 'linear' or 'circular' (default 'linear')
     'stops'       hue stops (default [2/3 0] linear, [0 1] circular)
    =========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function m = Bright(n,varargin)
0002 
0003 %Bright - Bright colormap (similar to HSV or JET, but brighter).
0004 %
0005 %  USAGE
0006 %
0007 %    m = Bright(n,<options>)
0008 %
0009 %    n              optional number of rows in output matrix (default = 100)
0010 %    <options>      optional list of property-value pairs (see table below)
0011 %
0012 %    =========================================================================
0013 %     Properties    Values
0014 %    -------------------------------------------------------------------------
0015 %     'hgamma'      gamma-like correction for hue (1 = no correction, default)
0016 %     'type'        either 'linear' or 'circular' (default 'linear')
0017 %     'stops'       hue stops (default [2/3 0] linear, [0 1] circular)
0018 %    =========================================================================
0019 
0020 % Copyright (C) 2009-2018 by Michaƫl Zugaro
0021 %
0022 % This program is free software; you can redistribute it and/or modify
0023 % it under the terms of the GNU General Public License as published by
0024 % the Free Software Foundation; either version 3 of the License, or
0025 % (at your option) any later version.
0026 
0027 % Default values
0028 hgamma = 1;
0029 type = 'linear';
0030 stops = [];
0031 linearStops = [2/3 0];
0032 circularStops = [0 1];
0033 
0034 % Optional parameter
0035 if nargin < 1,
0036     n = 100;
0037 elseif ischar(n),
0038     varargin = {n,varargin{:}};
0039     n = 100;
0040 elseif ~isdscalar(n,'>=0'),
0041     error('Incorrect value for ''n'' (type ''help <a href="matlab:help Bright">Bright</a>'' for details).');
0042 end
0043 
0044 % Check number of parameters
0045 if mod(length(varargin),2) ~= 0,
0046     error('Incorrect number of parameters (type ''help <a href="matlab:help Bright">Bright</a>'' for details).');
0047 end
0048 
0049 % Parse parameter list
0050 for i = 1:2:length(varargin),
0051     if ~ischar(varargin{i}),
0052         error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help Bright">Bright</a>'' for details).']);
0053     end
0054     switch(lower(varargin{i})),
0055         case 'hgamma',
0056             hgamma = varargin{i+1};
0057             if ~isdscalar(hgamma,'>=0'),
0058             error('Incorrect value for property ''hgamma'' (type ''help <a href="matlab:help Bright">Bright</a>'' for details).');
0059             end
0060         case 'stops',
0061             stops = varargin{i+1};
0062             if ~isdvector(stops,'>=0','<=1') || length(stops) < 2,
0063                 error('Incorrect value for property ''stops'' (type ''help <a href="matlab:help Bright">Bright</a>'' for details).');
0064             end
0065         case 'type',
0066             type = lower(varargin{i+1});
0067             if ~isastring(type,'linear','circular'),
0068             error('Incorrect value for property ''type'' (type ''help <a href="matlab:help Bright">Bright</a>'' for details).');
0069             end
0070         otherwise,
0071             error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help Bright">Bright</a>'' for details).']);
0072     end
0073 end
0074 
0075 % Default stops
0076 if isempty(stops),
0077     if strcmp(type,'circular'),
0078         stops = circularStops;
0079     else
0080         stops = linearStops;
0081     end
0082 end
0083 if strcmp(type,'circular') && stops(1) ~= stops(end) && abs(stops(1)-stops(end)) ~= 1,
0084     stops(end+1) = stops(1);
0085 end
0086 
0087 % Number of color band (transitions between stop pairs)
0088 nBands = length(stops)-1;
0089 
0090 % Construct color bands
0091 hsv = [];
0092 nn = round(n/nBands);
0093 for i = 1:nBands,
0094     hsv = [hsv ; linspace(0,1,nn)'.^(1/hgamma)*(stops(i+1)-stops(i))+stops(i)];
0095 end
0096 n = length(hsv);
0097 
0098 % Set saturation and value, then convert to RGB
0099 hsv(:,2) = 1;
0100 hsv(:,3) = 1;
0101 m = hsv2rgb(hsv);
0102

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005