Adaptive Colormap Function Creates a Colormap Specific to Data
Tristan Ursell
Nov 2013
Adaptive colormap
rgbslide(mat_in,...)
slide_map = rgbslide(...);
This function creates, on the fly, an active / adaptive colormap for the
data given by the matrix 'mat_in', and can be used in combination with
image generation in a figure. This can be very useful for coloring
data according to its absolute value. For instance, if your data ranges
from -rand to rand and you want the positive values in that image to be
zero=black --> positive number=red, and the negative values to be
zero=black --> negative numbers=blue -- the colormap would have to
actively adjust itself to the image data -- that is what this function
does. Try out the examples.
Another nice thing is that if you use zero_color = [0 0 0]; (i.e. black)
then the colormap is guaranteed to be increasing luminosity in each
direction (unlike most other colormaps, e.g. 'jet' or 'hsv').
This function has a number of options:
'zero_val' is the value that will map to the color 'zero_color',
the default is 0.
'low_val' is the value to which 'low_color' corresponds, if no value is
specified then 'low_val' will be min(mat_in(:)).
'high_val' is the value to which 'high_color' corresponds, if no value is
specified then 'high_val' will be max(mat_in(:)).
'zero_color' is a 1 x 3 color vector specifying the color of the value
'zero_val', the default is black (0 0 0).
'low_color' is a 1 x 3 color vector specifying the color of the lowest
value in the map, the default is blue (0 0.25 1).
'high_color' is a 1 x 3 color vector specifying the color of the highest
value in the map, the default is red (1 0.25 0).
The term 'equal' may be invoked to keep the colormapping around
'zero_val' constrained to equal slope on each side, or no argument will
allow the slopes to vary independently so as to maximize the color
contrast on either side of 'zero_val'.
'res' sets the resolution of the colormap, such that the output
'slide_map' will be res x 3 in size.
SEE ALSO: colormap, stretchlim
EXAMPLES:
dx=500;
Xpos=ones(dx,1)*(1:dx);
Ypos=Xpos';
Im1=cos(4*pi*Xpos/dx).*cos(6*pi*Ypos/dx)+5*((Xpos-dx/2).^2/dx^2+(Ypos-dx/2).^2/dx^2);
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1);
colorbar
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1,'equal');
colorbar
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1,'zero_color',[1 1 1]);
colorbar
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1,'zero_val',1);
colorbar
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1,'zero_val',-3);
colorbar
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1,'zero_val',5);
colorbar
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1,'high_color',[0 1 0.25],'low_color',[1 0 0.8]);
colorbar
figure;
imagesc(Im1)
axis equal tight
rgbslide(Im1,'low_val',-1/2,'high_val',2);
colorbar
figure;
imagesc(Im1)
axis equal tight
colormap(jet)
colorbar
Cita come
Tristan Ursell (2024). Adaptive Colormap Function Creates a Colormap Specific to Data (https://www.mathworks.com/matlabcentral/fileexchange/39453-adaptive-colormap-function-creates-a-colormap-specific-to-data), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Tag
Riconoscimenti
Ispirato: Zerocolor
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
Versione | Pubblicato | Note della release | |
---|---|---|---|
1.5.0.0 | corrected a small bug |
||
1.4.0.0 | matlab central uploaded the wrong file |
||
1.3.0.0 | shortened code, fixed a bug |
||
1.2.0.0 | Significant upgrades to the code, can now handle specifications of all control points, colors, and any resolution, with any input matrix values. |
||
1.1.0.0 | updates to the description and instructions. |
||
1.0.0.0 |