我正在尝试将彩色图像覆盖在灰度图像上。然而,当我尝试绘制"颜色条"并设置"气候"时。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
可以在此处找到单个图形/多个颜色图的参考http://www.mathworks.fr/support/solutions/en/data/1-GNRWEH/index.html
特别是使用图像时,可以使用"子图像"功能。
当自制的解决方案太棘手时,我还使用"matlabcentral"中的"FreezeColor"one_answers"cbfreeze"函数。http://www.mathworks.com/matlabcentral/fileexchange/7943-freezecolors-unfreezecolorshttp://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