如何添加"colorbar"并将"clim"设置为覆盖在灰度图像上的彩色图像? [英] How to add a 'colorbar' and set 'clim' to a colour image overlaid on a grey level image?
问题描述
我正在尝试将彩色图像叠加在灰度图像上.但是,当我尝试绘制'colorbar'并将其设置为'clim'时. Matlab总是根据下面的灰度图像生成一个色条.
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
推荐答案
单个图形/多个颜色图的参考可以在这里找到 http://www.mathworks.fr/support/solutions /en/data/1-GNRWEH/index.html
A reference for single figure/multiple colormaps can be found here http://www.mathworks.fr/support/solutions/en/data/1-GNRWEH/index.html
尤其是使用图像时,可以使用子图像"功能.
Using images in particular, one can use 'subimage' function.
当自制解决方案过于棘手时,我还会使用"matlabcentral"中的"FreezeColor"和"cbfreeze"功能. http://www.mathworks.com/matlabcentral/fileexchange/7943-freezecolors-unfreezecolors http://www.mathworks.com/matlabcentral/fileexchange/24371
I also use 'FreezeColor' and 'cbfreeze' functions from 'matlabcentral' when a home-made solution is too tricky. http://www.mathworks.com/matlabcentral/fileexchange/7943-freezecolors-unfreezecolors http://www.mathworks.com/matlabcentral/fileexchange/24371
一种简单而又懒惰的解决方案,用于在同一坐标轴上的多个图上保留颜色条:首先绘制彩色图像及其颜色条,冻结颜色条,然后在灰度图像上绘制(无透明度),最后绘制再次彩色图像(透明).
A straightforward - and lazy - solution for keeping a colorbar across multiple plots within the same axes: first plot the colour image and its colorbar, freeze the colorbar, then plot over the grey level image (no transparency), and finally plot the colour image again (transparency).
这是一段代码.
figure;
%first step: RGB image and colorbar
overlayImage = imagesc(colorImage, 'CDataMapping', 'scaled', 'HitTest', 'off');
alF = 0.5.*ones(size(colorImage, 1), size(colorImage, 2));
set(overlayImage, 'AlphaData', alF);
colorbar;
set(gca, 'CLim', [0 100]);
cbfreeze; %from 'COLORMAP and COLORBAR utilities' in Matlab Central
%second step: gray image (no transparency)
greyImagePlot = image(greyImage); colormap(gray); hold on;
%third step: plot colour image
overlayImage = imagesc(colorImage, ...
'CDataMapping', 'scaled', 'HitTest', 'off');
alF = 0.5.*ones(size(colorImage, 1), size(colorImage, 2));
set(overlayImage, 'AlphaData', alF);
axis off
axis image
这篇关于如何添加"colorbar"并将"clim"设置为覆盖在灰度图像上的彩色图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!