选择图像的区域

时间:2016-02-15 08:25:18

标签: matlab

我正在使用MATLAB 2015a。我想借助鼠标从图像中选择特定对象,以便它可以围绕对象制作方形,并且我想返回所选对象的像素。我该怎么办?帮助我。

1 个答案:

答案 0 :(得分:1)

getrect功能起到了作用。

来自文档:

  

rect = getrect允许您使用选择当前轴中的矩形   老鼠。使用鼠标单击并拖动所需的矩形。矩形   是一个四元素向量,形式为[xmin ymin width height]。至   将矩形约束为正方形,使用shift或右键单击   开始拖拽。

图片示例:

您可以使用这些坐标/尺寸作为图像矩阵的索引。

Im = imshow('moon.tif');

rect = getrect;
xmin = round( rect(1) )
ymin = round( rect(2) )
width = round( rect(3) )
height = round( rect(4) )

xvec = xmin:xmin+width;
yvec = ymin:ymin+height;
imshow( Im.CData( yvec, xvec ) );

功能图的示例:

t = 0:0.1:10;
y = sin(t);
plot( t, y );

然后拨打getrect

enter image description here

返回矩形坐标/尺寸:

ans =

    2.4309   -0.4665    4.5161    0.7230