问题
I would like to overlay two images in MATLAB (I
and imagesc(data)
) and then draw a rectangle on top of those. I2
specifies the transparency pattern in the following code. The rectangle becomes a line on top of the image. Can anyone tell me why the rectangle is not drawn correctly?
imshow(I);
hold on;
h = imagesc(data,[0,1]);
hold off;
I2 = ones(height,width) * 80;
set(h, 'AlphaData', I2);
rectangle('Position',[100,100,20,20]);
回答1:
Since we can't reproduce your code exactly without all the data, here is a complete example with sample images:
%# some sample images
I = imread('coins.png');
I_transp = imread('peppers.png');
%# create a gaussian mask for transparency
[r,c,~] = size(I_transp);
M = fspecial('gaussian', [r c], mean([r c]./5));
M = (M-min(M(:)))./range(M(:));
%# show overlayed images
figure, imshow(I, 'XData',[1 c], 'YData',[1 r]), hold on
hImg = imshow(I_transp);
set(hImg, 'AlphaData',M);
%# draw a rectangle
rectangle('Position',[355 220 100 100], 'LineWidth',2, 'EdgeColor','b');
来源:https://stackoverflow.com/questions/6602697/draw-a-rectangle-on-top-of-overlaid-images