0

我有两个图像:需要用 0.5 的恒定 alpha 映射im2覆盖。im1每当我设置'AlphaData'for im2(在im1下面显示)时,图形/轴的大小都会略有变化。如果我的坐标轴占据了整个图形,一些边框像素就会丢失。以下示例通过两个示例图像演示了此问题,其中im2有一个黄色边框,因此您可以清楚地注意到此问题:

close all;

frame_sz = [106 777];
% create a white im1
im1 = ones([frame_sz 3]);

% create im2 with a yellow border
im2 = zeros([frame_sz 3]);
im2(:,1,[1 2]) = 1;
im2(:,end,[1 2]) = 1;
im2(1,:,[1 2]) = 1;
im2(end,:,[1 2]) = 1;

% create the figure at a specific location with size equal to image
screen_sz = get(0,'ScreenSize');
fg_h = figure('units', 'pixels', 'position', ...
    [screen_sz([3 4])-frame_sz([2 1])-40 frame_sz([2 1])], ...
    'paperpositionmode', 'auto');
ax_h = axes('Parent',fg_h);

% show first image
imshow(im1, 'Parent',ax_h, 'InitialMagnification','fit');
hold on;
% display im2 ontop of im1
h = image(im2, 'Parent',ax_h);
% set the axis such that image occupies the whole figure
set(ax_h, 'Units','normalized', ...
    'position', [0 0 1 1], 'visible', 'off');
axis off;

%%%%%%%%%%%% PROBLEM HAPPENS HERE %%%%%%%%%%%%%
% as soon as I set the AlphaData couple of pixels 
%  go missing from the right and bottom side
set(h, 'AlphaData', ones(frame_sz([1 2]))*0.5);

无论我是使用 image() 叠加还是仅使用 image() 显示图像,都会出现问题。一旦我设置了 AlphaData,轴的大小就会发生轻微的变化并切断一些边界。

我该如何解决?

4

0 回答 0