在覆盖的图像上方绘制一个矩形 [英] draw a rectangle on top of overlaid images

查看:75
本文介绍了在覆盖的图像上方绘制一个矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MATLAB中叠加两个图像(Iimagesc(data)),然后在这些图像上绘制一个矩形. I2在以下代码中指定透明度模式.矩形变成图像顶部的一条线.谁能告诉我为什么矩形绘制不正确?

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]);    

推荐答案

由于我们无法在没有所有数据的情况下完全重现您的代码,因此以下是带有示例图像的完整示例:

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');

这篇关于在覆盖的图像上方绘制一个矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆