MATLAB Answers

I need to overlay a color map over a gray scale image with with the colorbar on the side.

128 views (last 30 days)
Chris
Chris on 20 Dec 2017
Commented: M J on 26 Aug 2019
I know there are similar post but I was unable to get them working. Attached is one matfile which contains 2 variables. I would like the colormap (Tmap) overlayed on a gray-scaled imaged on the variable 'x'. I also need all the zeroes not to show and and a colorbar shown on the side. Thanks for the assistance. You can see what I tried to do to get it working. Thanks for the help.
figure; imagesc(Tmap); colormap(jet); colorbar;
mask=Tmap>0;
figure; imshow(mask);
overlayImage=gray2ind(double(Tmap)/max(Tmap(:)),128);
overlayRGB=ind2rgb(overlayImage,jet(128));
x=im2double(x);
x=gray2ind(double(x)/max(x(:)),128);
vvv=[37 45]; %Set the colorbar axis
h=subimage(x);
set(h,'AlphaData',mask);
imagesc(Tmap);colormap(jet);colorbar; caxis(vvv);
hold on;
h=subimage(x);
set(h,'AlphaData',~mask)
h=gcf;
saveas(h,'NiceTherm')

  0 Comments

Sign in to comment.

Accepted Answer

Teja Muppirala
Teja Muppirala on 20 Dec 2017
Something like this maybe?
figure;
ax1 = axes;
imagesc(x);
colormap(ax1,'gray');
ax2 = axes;
imagesc(ax2,Tmap,'alphadata',Tmap>0);
colormap(ax2,'jet');
caxis(ax2,[min(nonzeros(Tmap)) max(nonzeros(Tmap))]);
ax2.Visible = 'off';
linkprop([ax1 ax2],'Position');
colorbar;

  3 Comments

Chris
Chris on 20 Dec 2017
That looks like it should work but I'm getting an error when I run it. The version I'm using is 2012a. it seems it doesn't like the line "imagesc(ax2,Tmap,'alphadata',Tmap>0);"
Error using image Incorrect number of arguments specified
Error in imagesc (line 40) hh = image(varargin{:},'CDataMapping','scaled');
M J
M J on 26 Aug 2019
Thank you, this works for me!
However, I fail to do this in a subplot. Can you help me with this?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by