How can I use same color range on subimages?

Hi, I want, that my all subimages have the same colour range. I´m using caxis command but it doesn´t work. Can you help me? I'm lost. (sorry for my english)
bottom = min(min(min(mmin1,mmin2),mmin3),mmin4);
top = max(max(max(mmax1,mmax2),mmax3),mmax4);
subplot(3,2,1+2)
subimage(imresize(imag,20),colormap(jet));
axis off
caxis manual
caxis([bottom top]);
colorbar;
subplot(3,2,2+2)
subimage(imresize(imag,20),colormap(jet)),
axis off
caxis manual
caxis([bottom,top]);
colorbar;

2 commentaires

Adam
Adam le 5 Mar 2015
That seems like generally what you should be doing though I always use explicit axes handles for any plotting-related functions to ensure it is being applied to the correct axes.
I can't run your code though as I don't have all the variables defined that you have.
In my code, mmin1-mmin4 are minims of matrix (i have 4 matrix, M1(:,:,id_1)...M4(:,:,id_4) size is 10x16 and values in range -2:2 (e.g. -0.03) and first imag is
I = mat2gray(M1(:,:,id_m1));
[imag,map] = gray2ind(I);
where, M1(:,:,id_m1) is one of matrix, second imag ist same but for second matrix.
And I want to display one colormap on all of these imag, i want display same values of matrix in same colour.

Connectez-vous pour commenter.

 Réponse acceptée

Image Analyst
Image Analyst le 5 Mar 2015

0 votes

Not sure what you're asking about. If you just display a bunch of grayscale images and then apply a colormap, it has all images use the same colormap so that the same gray scale intensities are mapped to the same colors. In R2014b you can change that and have different colormaps with different axes. What version do you have and why aren't all your images having the same color map now? They should have, unless you're using R2014b and specifically went to the trouble to make then not use the same colormaps.

5 commentaires

I want to apply one colormap on whole figure...I have 4 matrix with some values and i want that same values had same colours. Im using matlab R2014b.
Image Analyst
Image Analyst le 6 Mar 2015
That's the way it is now. Just display them and call colormap. Don't mess with caxis individually. If not, then prepare a small demo using standard demo images to illustrate what you're not getting.
It's better by I still don't have result what i need.
M = rand([10,16,4],'single');
bottom = min(min(min(M)))
top = max(max(max(M)))
figure
I = mat2gray(M(:,:,1));
[imag,map] = gray2ind(I);
subplot(3,2,1)
imshow(imresize(imag,20));
I2 = mat2gray(M(:,:,2));
[imag2,map] = gray2ind(I2);
subplot(3,2,2)
imshow(imresize(imag2,20));
I3 = mat2gray(M(:,:,3));
[imag3,map] = gray2ind(I3);
subplot(3,2,3)
imshow(imresize(imag3,20));
I4= mat2gray(M(:,:,4));
[imag4,map] = gray2ind(I4);
subplot(3,2,4)
imshow(imresize(imag4,20));
colormap(jet);
I want maximum value display by red color and minimum value blue...now all values are the shades of blue.
You're doing all kinds of stuff you should not be doing. Why do you think you need to call mat2gray and gray2ind()? You should not. Try this:
M = rand([10,16,4],'single');
bottom = min(M(:))
top = max(M(:))
subplot(2, 2,1)
imshow(imresize(M(:,:,1),20));
colorbar;
subplot(2, 2,2)
imshow(imresize(M(:,:,2),20));
colorbar;
subplot(2, 2,3)
imshow(imresize(M(:,:,3),20));
colorbar;
subplot(2, 2,4)
imshow(imresize(M(:,:,4),20));
colorbar;
colormap(jet(256));
Thank you so much! I just need add caxis and it works.
imshow(imresize(imag,20));
caxis([bottom top]);
colorbar;
I call mat2gray and gray2ind becouse i tried a lot of things before and I don't delete it...I'm still beginer in matlab so really thank you!

Connectez-vous pour commenter.

Plus de réponses (1)

Adam
Adam le 6 Mar 2015

0 votes

Ok, now that I have looked at the help page for subimage as I have never used it, it works by converting your image to true colour for display by applying the colourmap you give. That means it will be unaffected by changes to the 'CLim' property (e.g. via caxis).
If you wish to change the colour scaling you will have to do it on the image (or the colourmap) before you call subimage because once it converts to true RGB the colourmap becomes irrelevant.
It is confusing that Matlab allows you to put a colourbar on the screen even for images that are unaffected by it, but that is just the way it works.

1 commentaire

Finally i don't use subimage but imshow after call subplot...like this
imag = M1(:,:,id_m1);
subplot(3,2,1+2)
imshow(imresize(imag,20));
caxis([bottom top]);
colorbar;
colormpat(jet(256));
and it finally work, thank you for your help.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by