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

10 ビュー (過去 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 Center および File ExchangeBlue についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by