How to add a 'colorbar' and set 'clim' to a colour image overlaid on a grey level image?
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Aaronne
el 27 de Jun. de 2013
Comentada: Image Analyst
el 20 de Jun. de 2014
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 comentarios
Respuesta aceptada
Sean de Wolski
el 27 de Jun. de 2013
I asked the same thing a few years ago :)
2 comentarios
Sean de Wolski
el 27 de Jun. de 2013
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.
Más respuestas (1)
C Stewart
el 20 de Jun. de 2014
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 comentario
Image Analyst
el 20 de Jun. de 2014
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 ?
Ver también
Categorías
Más información sobre Blue en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!