Why does my colour bar not go up to the maximum values in the matrix?
4 views (last 30 days)
Show older comments
Goncalo Costa
on 17 Aug 2023
Commented: Dyuman Joshi
on 17 Aug 2023
I am imaging a matrix A with the following code:
I = imgaussfilt(A,2);
I2 = imsharpen(I);
I3 = imresize(I2, 5);
figure(3), imagesc(I3)
axis equal tight xy
set(gca,'linewidth',1.0,'fontsize',20)
xlabel('X [mm]')
ylabel('Y [mm]')
c1=colorbar('LineWidth',1.0,'FontSize',20)
and I am checking what the maximum values in the matrix that I am plotting are:
max(max(A))
min(min(A))
In this case the maximum value is 2.7634 and the minimum is 0.9786, but the plot that I obtain is the following:
Based on the distance between 1.5 and 2 we can see that the maximum value is not presented in the colorbar and we can see that the minimum value is also not presented.
Is this because these must be isolated values and therefore negligible in the colour plot? Or is the code doing something weird?
0 Comments
Accepted Answer
Dyuman Joshi
on 17 Aug 2023
Edited: Dyuman Joshi
on 17 Aug 2023
"and I am checking what the maximum values in the matrix that I am plotting are:"
And as you can observe, values in I3 are not equal to values in A, as you have performed operations on A to obtain I3, which have changed the values accodring to the functions implemented.
2 Comments
Dyuman Joshi
on 17 Aug 2023
"I thought that the scaling meant that the highest value in the colour bar would be the maximum value of A..."
Not A, I3.
The input to imagesc() is I3, not A. And as you are plotting I3, you should check the values of I3.
load('A.mat')
I = imgaussfilt(A,2);
I2 = imsharpen(I);
I3 = imresize(I2, 5);
figure(3)
imagesc(I3)
axis equal tight xy
set(gca,'linewidth',1.0,'fontsize',20)
xlabel('X [mm]')
ylabel('Y [mm]')
c1=colorbar('LineWidth',1.0,'FontSize',20);
%Get the limits of the colorbar
clim
%Get the minimum and maximum values of I3
[min(I3,[],'all') max(I3,[],'all')]
As you can see, they are in fact, equal.
"If I have a bunch of images/matrices, how could I normalise the colour to the overall maximum and minimum of all images?"
Do you want to perform the same operations as mentioned above on the bunch of images/matrices, and show them in a tiled layout?
More Answers (0)
See Also
Categories
Find more on Orange 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!