assigning values in color bar
Afficher commentaires plus anciens
Hello,
I currently have an image that ranges from 0-1 and is in grayscale. I then assign the image to a new colormap which produces the desired colormap of 0-1. This part works well, however, for the next step I would like to reassign the colorbar to show values from 17-27 instead of 0-1, as the 0-1 represents 17-27*C. Is there a way I can reassign the values on the colorbar to show the 17-27 instead of 0-1?
Thanks for the help!
I = im2double(Image);
I2 = I(:,:,1);
colormap('jet');
x = linspace(0,100,640);
y = linspace(100,0,640);
z = I(:,:,3);
zmin = min((min(z)));
zmax = max((max(z)));
surf(x,y,z,'EdgeColor','none')
view(0,90)
colorbar
Réponse acceptée
Plus de réponses (1)
Voss
le 3 Jan 2024
min_val = 17;
max_val = 27;
N = max_val-min_val+1;
t = linspace(0,1,N); % tick locations (0, 0.1, 0.2, ..., 1)
tl = linspace(min_val,max_val,N); % tick label values (17, 18, 19, ..., 27)
colorbar('Ticks',t,'TickLabels',tl);
1 commentaire
Example:
% some image data:
Image = randi([0 255],640,640,3,'uint8');
% your code
I = im2double(Image);
I2 = I(:,:,1);
colormap('jet');
x = linspace(0,100,640);
y = linspace(100,0,640);
z = I(:,:,3);
zmin = min((min(z)));
zmax = max((max(z)));
surf(x,y,z,'EdgeColor','none')
view(0,90)
% my suggestion:
min_val = 17;
max_val = 27;
N = max_val-min_val+1;
t = linspace(0,1,N); % tick locations (0, 0.1, 0.2, ..., 1)
tl = linspace(min_val,max_val,N); % tick label values (17, 18, 19, ..., 27)
cb = colorbar('Ticks',t,'TickLabels',tl);
% add a colorbar label too:
cb.Label.String = '°C';
cb.Label.Rotation = 0;
Catégories
En savoir plus sur Basic Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

