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

DGM
DGM le 3 Jan 2024
Why not just scale it appropriately instead of trying to fake it? Don't need to use surf either.
% you have a single-channel image that's within unit-scale
I = im2double(imread('cameraman.tif'));
% rescale it such that 0,1 correspond to 17 and 27
inrange = [0 1];
outrange = [17 27];
Irescaled = rescale(I,outrange(1),outrange(2), ...
'inputmin',inrange(1),'inputmax',inrange(2));
% display it
imagesc([0 100],[100 0],Irescaled);
set(gca,'ydir','normal')
colormap('jet');
colorbar
Note that I'm mapping 0 and 1 to [17 27]. I'm not mapping the data extrema to [17 27].

Plus de réponses (1)

Voss
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;

Connectez-vous pour commenter.

Catégories

En savoir plus sur Color and Styling 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!

Translated by