Colormap with different color transition

조회 수: 31 (최근 30일)
Hsin Cheng
Hsin Cheng 2023년 5월 9일
편집: DGM 2023년 5월 9일
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에서 Color and Styling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by