2

我使用以下示例代码在背景图像上叠加索引图像(在下面的示例中,它是 RGB,但对于我的问题,背景是灰色的 sacle 图像)。然后我的问题是:

  1. 如何在叠加图像的一侧显示颜色条?颜色条应该是覆盖索引图像的颜色条而不是背景图像的颜色条。

  2. 如何修复覆盖索引图像的颜色图范围?我有几对灰度背景+叠加索引图像(使用'jet'彩色图)。我需要它们以相同的比例显示。我尝试使用set(iim2,'caxis', [0 1]);,但 Matlab 中的“图像”没有“caxis”的属性。

请帮助,非常感谢!

% Create the background
% This example uses a blend of colors from left to right, converted to a TrueColor image
% Use repmat to replicate the pattern in the matrix
% Use the "jet" colormap to specify the color space
bg = ind2rgb(repmat(1:64,64,1),jet(64));

% Create an image and its corresponding transparency data
% This example uses a random set of pixels to create a TrueColor image
im = rand(100,100,3);
% Make the image fade in from left to right by designing its alphadata
% Use repmat to replicate the pattern in the transparency fading
imAlphaData = repmat(0:1/size(im,2):1-1/size(im,2),size(im,1),1);

% Display the images created in subplots
hf = figure('units','normalized','position',[.2 .2 .6 .6]);
ax1 = subplot(2,3,1);
ibg = image(bg);
axis off
title('Background')
ax2 = subplot(2,3,4);
iim = image(im);
axis off
title('Image without transparency yet')

% Now set up axes that overlay the background with the image
% Notice how the image is resized from specifying the spatial
% coordinates to locate it in the axes.
ax3 = subplot(2,3,[2:3, 5:6]);
ibg2 = image(bg);
axis off
hold on
% Overlay the image, and set the transparency previously calculated
iim2 = image(im,'XData',[30 50],'YData',[10 30]);
set(iim2,'AlphaData',imAlphaData);
title(sprintf('Using transparency while overlaying images:\nresult is multiple image objects.'))
4

0 回答 0