Colormap with different color transition
48 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (2)
KSSV
le 9 Mai 2023
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)']
pcolor(peaks(50))
colormap(cmap)
Like wise do for all the colors and jlin them into 256x3 matrix.
DGM
le 9 Mai 2023
Modifié(e) : DGM
le 9 Mai 2023
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]))
0 commentaires
Voir également
Catégories
En savoir plus sur Colormaps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!