How to add a 'colorbar' and set 'clim' to a colour image overlaid on a grey level image?
13 次查看(过去 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
0 个评论
采纳的回答
Sean de Wolski
2013-6-27
I asked the same thing a few years ago :)
2 个评论
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
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
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 Exchange 中查找有关 Blue 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!