Reputation: 35525
I have a similar question than the one in this post.
I have a grayscale image and I plot points on it. Fro plotting the points I use colormap('jet')
but as I want the image to be grayscale, after plotting the points I reset the colormap, colormap('gray')
.
But I want to show a colorbar! And the colorbar is plotted in grayscale, not 'jet'. How can I do that?
EDIT: I want a Colorbar showing the color of the points!
Upvotes: 2
Views: 1947
Reputation: 38052
As discussed here, there's a few ways:
If you have the image processing toolbox, use subimage
to create an independent image with a separate colormap. Then plot the image, your points, and join them into one using linkaxes
.
Use freezeColors from the file exchange (or multiple colormaps, which I haven't ever tested personally). This is a very easy way to create a larger colormap, and automatically selecting the right portion of the colormap for display of images and colorbars.
As answered by anandr, convert your greyscale image to RGB; Matlab doesn't use colormaps on RGB images, which leaves you freedom to plot your points and show their colorbar independent of the image.
Example code for (3):
I = imread('cameraman.tif');
imshow(cat(3,I,I,I))
hold on
x = @() round(size(I,1) * rand(50,1));
y = @() round(size(I,2) * rand(50,1));
plot(x(), y(), 'r.')
plot(x(), y(), 'g.')
plot(x(), y(), 'b.')
colormap('jet')
colorbar
result:
Upvotes: 2
Reputation: 1672
You should convert your image to RGB by putting the same data into R-, G-, and B-channels (this will be grayscale RGB image). Colormap in MatLab is not applied to RGB images, only to indexed ones. Then plot your points over the image with colormap you like.
Upvotes: 5