draw a rectangle on top of overlaid images

試著忘記壹切 提交于 2019-12-21 21:23:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!