Problem with colorbar and values of scale
Show older comments
I have this image in HSV colorbar, regarding a density parameter.
Values range from 0 (air) to a maximum of 10, which was my prerrogative (it only goes up to 7.5 though).
What I want to know is why the scale starts at 0.5, and not 0? Air we consider of zero density (although it is not true, for interaction with X-rays we can consider it so)
Before someone asks, I already verified the matrix of the density variable and there is zeros around the sample, which appears in the image.
My code below:
figure;
image(rho);
colormap(hsv(ceil(rhomax-rhomin)));
cbh = colorbar('location', 'SouthOutside');
set(cbh, 'Units', 'normal', 'Xtick',0:0.5:10); %(I thought this part would make the values start from 0)
text(3.5, -1, 'Densidade (g/cm³)', 'Parent', cbh);

Answers (1)
Image Analyst
on 8 May 2014
0 votes
Let's say that rho ranged from 0.7 to 7.5. So rhoMax-rhoMin = 7.5-.5 = 7. So you will have 7 color steps when hsv(7) returns. And that's what you have: 7 color steps. It makes those steps (i.e. the tick mark labels) go from rhoMax to rhoMax, which is the range in your image.. If your rho went from 1001 to 1009, you'd have 8 color steps (1009 - 1001( and the tick marks would go from 1001 to 1009 because that's what's in your image. Does that make sense?
23 Comments
Haimon
on 8 May 2014
Image Analyst
on 9 May 2014
How are you so sure that rhoMin is zero? What does this say in the command window?
min(rho(:))
max(rho(:))
rhomin
rhomax
Haimon
on 9 May 2014
Haimon
on 9 May 2014
Image Analyst
on 9 May 2014
Edited: Image Analyst
on 9 May 2014
I don't have your data so I can't verify that. All I can do is generate some sample data in the same range, and it works fine. What does this do for you:
rho = 7 * rand(700,700);
min(rho(:))
max(rho(:))
imshow(rho, []);
colormap(hsv(7));
colorbar
Haimon
on 9 May 2014
Image Analyst
on 9 May 2014
OK, so if your min is near zero, the bottom of the colorbar will be 0 and top of the color bar will be 7. Keep in mind that there does not always seem to be a tick mark at the very ends. So in your case, the min of your data must be near 0.5 and the max near 7.5 (since your tick marks seem to be at the ends).
Haimon
on 10 May 2014
Image Analyst
on 10 May 2014
I can't do much more until you attach your data.
Haimon
on 10 May 2014
Image Analyst
on 10 May 2014
Nope, sorry.
Haimon
on 10 May 2014
Haimon
on 13 May 2014
Image Analyst
on 13 May 2014
No - extremely swamped with my regular job. Maybe on the weekend... Reply to this so I'll see you as the latest poster then. If I'm the last one to reply in a post, I normally don't open it up again.
Haimon
on 13 May 2014
Haimon
on 31 May 2014
Image Analyst
on 31 May 2014
I downloaded your data. Here's my code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
load('C:\Users\Mark\Documents\Temporary\rho.mat');
minValue = min(rho(:));
maxValue = max(rho(:));
fprintf('The min rho value = %f.\nThe max rho value = %f.\n', ...
minValue, maxValue);
imshow(rho, []);
colormap(hsv(7));
cbh = colorbar('location', 'SouthOutside');
set(cbh, 'Units', 'normal', 'Xtick',0:0.5:10); %(I thought this part would make the values start from 0)
text(3.5, -1, 'Densidade (g/cm³)', 'Parent', cbh);
Here's my image:

Do you see any problem with it?
Haimon
on 31 May 2014
Image Analyst
on 31 May 2014
It's not figure. It seems to be image(). image() causes the colorbar to start incorrectly at 0.5, while imshow() does it correctly and starts it at 0. I don't know why.
Haimon
on 2 Jun 2014
Image Analyst
on 2 Jun 2014
You must have changed the colormap.
Image Analyst
on 3 Jun 2014
I give the same answer as in your duplicate question: http://www.mathworks.com/matlabcentral/answers/132156#comment_217525
Categories
Find more on Blue in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
