Colormap with different color transition

44 次查看(过去 30 天)
I am using the colormap "turbo". The transition of color is red--orange--yellow--green--light blue--dark blue. Can I create a similar smooth colormap with a different color transition? For example: green--blue--purple--red--orange--yellow. I would also like to have 256 colors. Is there an easy way to do that?
I know that MATLAB uses three-column data format to specify each color, but I don't know how to generate a beautiful color transition by manipulating the digits.
Thank you for any input.

回答(2 个)

KSSV
KSSV 2023-5-9
USe RGB color values. For this use the link: https://www.rapidtables.com/web/color/RGB_Color.html
Fix two colrs, initial color and final color and then use linspace.
EXample:
green = [0 255 0]/255 ;
blue = [0 0 255]/255 ;
n = 10 ;
cmap = [linspace(green(1),blue(1),n)' linspace(green(2),blue(2),n)' linspace(green(3),blue(3),n)']
cmap = 10×3
0 1.0000 0 0 0.8889 0.1111 0 0.7778 0.2222 0 0.6667 0.3333 0 0.5556 0.4444 0 0.4444 0.5556 0 0.3333 0.6667 0 0.2222 0.7778 0 0.1111 0.8889 0 0 1.0000
pcolor(peaks(50))
colormap(cmap)
Like wise do for all the colors and jlin them into 256x3 matrix.
  1 个评论
Hsin Cheng
Hsin Cheng 2023-5-9
Thank you very much. I found that MATLAB has a built-in tool "colormapeditor" that really fits my need.

请先登录,再进行评论。


DGM
DGM 2023-5-9
编辑:DGM 2023-5-9
If you want to have a color table with multiple breakpoints, It's easier to just use interp1().
% new color table length
ncolors = 100;
% some approximate breakpoint colors
% green--purple--yellow
CT0 = [0.189 0.338 0.145;
0.7 0.0482 0.423;
0.978 0.765 0.0557];
% interpolate
x0 = linspace(0,1,size(CT0,1));
xf = linspace(0,1,ncolors);
CT = interp1(x0,CT0,xf,'linear');
% clamp values
CT = imclamp(CT); % your new color table
% display the CT as an image for sake of visualization
image(permute(flipud(CT),[1 3 2]))
That said, if it's important that the CT has particular properties (monotonic, linear, or symmetric perceived brightness), then it's usually better to do the interpolation in a different color space.
% new map length
ncolors = 100;
% some approximate breakpoint colors
% green--purple--yellow
CT0 = [0.189 0.338 0.145;
0.7 0.0482 0.423;
0.978 0.765 0.0557];
% convert to LAB
CT0 = rgb2lab(CT0);
% enforce some new L if it's desired for L to be ideally linear or symmetric
newL = [0.1 0.5 0.9]*100;
CT0(:,1) = newL;
% interpolate
x0 = linspace(0,1,size(CT0,1));
xf = linspace(0,1,ncolors);
CT = interp1(x0,CT0,xf,'linear');
% convert back
CT = imclamp(lab2rgb(CT)); % your new color table
% display the CT as an image for sake of visualization
image(permute(flipud(CT),[1 3 2]))

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by