Home > atmlab > graphs > zerobright.m

zerobright

PURPOSE ^

ZEROBRIGHT Rescale and centre colourmap so that brightest colour shows 0

SYNOPSIS ^

function zerobright()

DESCRIPTION ^

 ZEROBRIGHT Rescale and centre colourmap so that brightest colour shows 0

 Rescale and centre the colourmap for the currently active figure so that
 the brightest colour will correspond to the value 0.  This is
 particularly useful when the colourmap contains the colour white and
 colours on one side of white are quite different from colours on the
 other side of white.  In this case, the effect of applying zerobright is
 that negative values get one colour, positive values another, and values
 around zero will be white.

 The function takes no input arguments and has no output arguments.

 See also: zerowhite, zerowhite2

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

zerobright.m

SOURCE CODE ^

0001 function zerobright()
0002 % ZEROBRIGHT Rescale and centre colourmap so that brightest colour shows 0
0003 %
0004 % Rescale and centre the colourmap for the currently active figure so that
0005 % the brightest colour will correspond to the value 0.  This is
0006 % particularly useful when the colourmap contains the colour white and
0007 % colours on one side of white are quite different from colours on the
0008 % other side of white.  In this case, the effect of applying zerobright is
0009 % that negative values get one colour, positive values another, and values
0010 % around zero will be white.
0011 %
0012 % The function takes no input arguments and has no output arguments.
0013 %
0014 % See also: zerowhite, zerowhite2
0015 
0016 oldcmap = colormap();
0017 datarange = caxis();
0018 ncolours = size(oldcmap, 1);
0019 
0020 if sign(datarange(1)) == sign(datarange(2))
0021     error(['atmlab:' mfilename ':nonzero'], ...
0022         'Data do not contain zero');
0023 end
0024 
0025 [~, current_white] = max(mean(oldcmap, 2)); 
0026 current_zero_pos = abs(datarange(1)/diff(datarange)) * size(oldcmap, 1);
0027 
0028 % match 1:current_white to 1:current_zero_pos
0029 current_zero_pos * size(oldcmap, 1);
0030 oldcmap(1:current_white, :);
0031 
0032 low = interp1(1:current_white, ...
0033               oldcmap(1:current_white, :), ...
0034               linspace(1, current_white, current_zero_pos));
0035 
0036 hi = interp1(vec2col(1:ncolours - current_white), ...
0037              oldcmap(current_white+1:ncolours, :), ...
0038              linspace(1, ncolours-current_white, ncolours - current_zero_pos));
0039 
0040 colormap([low; hi]);
0041 
0042 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005