我正在尝试将彩色图像叠加在灰度图像上。但是,当我尝试绘制'colorbar'并设置'clim'时。 Matlab总是根据下面的灰度图像生成一个颜色条。
但是,我想获得叠加彩色图像的颜色条。任何建议都会很感激。非常感谢。
%% 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 :(得分:3)
此处可以找到单个图形/多个颜色图的参考 http://www.mathworks.fr/support/solutions/en/data/1-GNRWEH/index.html
特别使用图像,可以使用“子图像”功能。
当自制解决方案太棘手时,我也使用'matlabcentral'中的'FreezeColor'和'cbfreeze'功能。 http://www.mathworks.com/matlabcentral/fileexchange/7943-freezecolors-unfreezecolors http://www.mathworks.com/matlabcentral/fileexchange/24371
一种直观且懒惰的解决方案,用于在相同轴上保持多个绘图的颜色条:首先绘制彩色图像及其颜色条,冻结颜色条,然后绘制灰度图像(无透明度),最后绘制再次出现彩色图像(透明度)。
这是一段代码。
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