MATLAB:图像AlphaData改变图形大小

时间:2013-04-23 02:28:42

标签: image matlab size border figure

我有两张图片:im2需要覆盖im1,并且常量alpha贴图为0.5。每当我为'AlphaData'设置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,轴的大小会稍微改变并切断一些边界。

我该如何解决这个问题?

0 个答案:

没有答案