How to add a 'colorbar' and set 'clim' to a colour image overlaid on a grey level image?

38 次查看(过去 30 天)
Hi all,
I am trying to overlay a colour image on a grey level image. However, when I try to plot the 'colorbar' and set the 'clim'. Matlab always produce a colorbar according to the underneath grey level image.
However, I want to get the colorbar for the overlaid colour image. Any suggestions would be appreciate. Thanks a lot.
%%Example codes:
greyImage = imread('AT3_1m4_08.tif');
colorImage = imread('hestain.png');
figure,
greyImagePlot = image(greyImage); colormap(gray); hold on;
overlayImage = imagesc(colorImage, ...
'CDataMapping', 'scaled', 'HitTest', 'off');
alF = 0.5.*ones(size(colorImage, 1), size(colorImage, 2));
set(overlayImage, 'AlphaData', alF);
colorbar; % This will show a grey scale colorbar not the colour one I want
set('CLim', [0 100]); % Also, the colormap limit here is not working
axis off
axis image

采纳的回答

Sean de Wolski
Sean de Wolski 2013-6-27
  2 个评论
Aaronne
Aaronne 2013-6-27
No working. My question is not set a colorbar of a certain range, but the colorbar of the overlaid color image.
Sean de Wolski
Sean de Wolski 2013-6-27
Ahh. So your color image is still RGB. It's not being shown as indexed into the colormap which is why it's not showing up. In order for it to show up with the colorbar, you will have to convert it to an indexed image using ind2rgb.
%%Example codes:
greyImage = imread('AT3_1m4_08.tif');
colorImage = imread('hestain.png');
[colorImg,map] = rgb2ind(colorImage,256);
figure,
greyImagePlot = image(greyImage);
colormap([gray(256);map]);
hold on;
overlayImage = image(double(colorImg)+256, ...
'CDataMapping', 'scaled', 'HitTest', 'off');
alF = 0.5.*ones(size(colorImage, 1), size(colorImage, 2));
set(overlayImage, 'AlphaData', alF);
%colorbar; % This will show a grey scale colorbar not the colour one I want
%set('CLim', [0 100]); % Also, the colormap limit here is not working
axis off
axis image
%Now this
h = colorbar;
set(h,'YLim',[257 512]);
As you can see though, the conversion to indexed image defintiely causes a loss of resolution.

请先登录,再进行评论。

更多回答(1 个)

C Stewart
C Stewart 2014-6-20
I just had the same problem - here's one workaround which seems to leave a functional colorbar:
(1) plot the color image (2) make the colorbar (3) plot the grayscale (4) send the grayscale to the back (uistack(h,'bottom'))
however this surely shouldn't be required... mathworks any comment???
  1 个评论
Image Analyst
Image Analyst 2014-6-20
Sean works for the Mathworks.
I don't see the need. Isn't the RGB color image just the grayscale image with the colorbar applied? If so, then why is it not okay to show the gray scale image only, with the colormap applied and the color bar showing? It would be the same thing. Why is there a need to display a true color RGB image when the pseudocolored grayscale image would look identical ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 White 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by