Why does my colour bar not go up to the maximum values in the matrix?

조회 수: 5 (최근 30일)
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?

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 8월 17일
편집: Dyuman Joshi 2023년 8월 17일
"and I am checking what the maximum values in the matrix that I am plotting are:"
No, you are checking the values of A, whereas you are plotting the values of I3 via imagesc.
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
Goncalo Costa
Goncalo Costa 2023년 8월 17일
Oh .... but it still isn't quite clear to me how this scaling works? I thought that the scaling meant that the highest value in the colour bar would be the maximum value of A and so on for the minimum. If this is not the case, how can there be consistency between the values in A and the colours shown?
If I have a bunch of images/matrices, how could I normalise the colour to the overall maximum and minimum of all images?
Thanks for your help.
Dyuman Joshi
Dyuman Joshi 2023년 8월 17일
"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
ans = 1×2
0.9933 2.2033
%Get the minimum and maximum values of I3
[min(I3,[],'all') max(I3,[],'all')]
ans = 1×2
0.9933 2.2033
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?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by