主要内容

roipoly

指定感兴趣的多边形区域(ROI)

描述

Create Polygon Interactively

BW= roipoly创建与当前图中显示的图像关联的交互式多边形工具。roipolyreturns the mask as a binary image, setting pixels inside the ROI to1和pixels outside the ROI to0

With this syntax and the other interactive syntaxes, the polygon selection tool blocks the MATLAB®命令行直到完成操作。有关使用多边形选择工具的更多信息,请参见互动行为

BW= roipoly(I)显示灰度或RGB图像I在图形窗口中,创建与图像关联的交互式多边形选择工具。

Create Polygon by Specifying Vertices

example

BW= roipoly(I,xi,)指定x,y) coordinates of polygon vertices as (xi,)。

BW= roipoly(xref,yref,I,xi,)指定世界坐标系中多边形顶点的坐标xrefyref。多边形顶点有(x,y) coordinatesxiin this coordinate system.

指定其他输出选项

[BW,xi2,yi2] = roipoly(___)also returns the coordinates of the vertices of the closed polygon,xi2yi2。您可以使用任何其他语法的输入参数。

[xrefout,yrefout,BW,xi2,yi2] = roipoly(___)还返回图像限制xrefoutyrefout

roipoly(___)没有输出参数将在新的图形窗口中显示所得的掩码图像。

例子

全部收缩

在工作区中阅读图像。

i = imread('eight.tif');

Define the vertices of the mask polygon.

c = [222 272 300 270 221 194]; r = [21 21 75 121 121 75];

Create the binary mask image.

bw = roipoly(i,c,r);

Display the original image and the polygonal mask.

imshow(i)

Figure contains an axes object. The axes object contains an object of type image.

figure imshow(BW)

Figure contains an axes object. The axes object contains an object of type image.

输入参数

全部收缩

灰度或RGB图像,指定为m-经过-n数字矩阵或m-经过-n-by-3数字阵列, respectively.

x- 多边形顶点的坐标,指定为数字向量的长度与。如果您在世界坐标系中指定图像限制xref, thenxi在此坐标系中。否则,xiis in the default coordinate system.

y- 多边形顶点的坐标,指定为数字向量的长度与xi。如果您在世界坐标系中指定图像限制yref, then在此坐标系中。否则,is in the default coordinate system.

世界坐标中的图像限制thex-dimension, specified as a 2-element numeric vector of the form [xminxmax]。的价值xref设置图像XData

世界坐标中的图像限制they-dimension, specified as a 2-element numeric vector of the form [Yminymax]。的价值yref设置图像YData

Output Arguments

全部收缩

Binary image, returned as anm-经过-n逻辑矩阵。

Data Types:logical

x- 封闭多边形顶点的坐标,作为数字向量的长度与yi2。向量中的第一个也是最后一个元素是相同的,因此多边形是关闭的。如果您在世界坐标系中指定图像限制xref, thenxi2在此坐标系中。否则,xi2is in the default coordinate system.

y- 封闭多边形顶点的坐标,作为数字向量的长度与xi2。向量中的第一个也是最后一个元素是相同的,因此多边形是关闭的。如果您在世界坐标系中指定图像限制yref, thenyi2在此坐标系中。否则,yi2is in the default coordinate system.

世界坐标中的图像限制thex-dimension, returned as a 2-element numeric vector of the form [xminxmax]。如果您在世界坐标系中指定图像限制xref, thenxrefoutis equal toxref。否则,xrefoutis equal to the original imageXData

世界坐标中的图像限制they-dimension, returned as a 2-element numeric vector of the form [Yminymax]。如果您在世界坐标系中指定图像限制yref, thenyrefoutis equal toyref。否则,yrefoutis equal to the original imageYData

More About

全部收缩

互动行为

多边形选择工具使您可以使用鼠标进行交互选择和调整多边形顶点。

当多边形工具处于活动状态时,指针会更改为跨发when you move the pointer over the image in the figure. Using the mouse, you specify the region by selecting vertices of the polygon. You can move or resize the polygon using the mouse. When you are finished positioning and sizing the polygon, create the mask by double-clicking, or by right-clicking inside the region and selecting创建口罩从上下文菜单。

The figure illustrates a polygon defined by multiple vertices. The following table describes all the interactive behavior of the polygon tool.

互动行为 描述
关闭多边形。(完成利益区域。)

Use any of the following mechanisms:

  • Move the pointer over the initial vertex of the polygon that you selected. The pointer changes to a circle。单击任一鼠标按钮。

  • 双击左鼠标按钮。此动作在鼠标指针下的点上创建一个顶点,并绘制一条直线,将该顶点与初始顶点连接起来。

  • 右键单击鼠标。这绘制了连接与初始顶点选择的最后一个顶点的线路;它不会在鼠标下的点创建新顶点。

Moving the entire polygon 将指针移入区域内。The pointer changes to a fleur shape。Click and drag the polygon over the image.
Deleting the polygon

PressBackspace,Escape或者删除,或在区域内右键单击并选择取消从上下文菜单。

Note: If you delete the ROI, the function returns empty values.

Moving a vertex. (Reshaping the region-of-interest.) 将指针移到顶点。指针变为圆。单击并将顶点拖到其新位置。
添加一个新顶点。 Move the pointer over an edge of the polygon and press theAkey. The pointer changes shape to。单击鼠标左键在边缘上的那个点创建一个新顶点。
删除顶点。(重塑利益区域。) 将指针移到顶点上。指针变为圆。右键单击并选择删除顶点从上下文菜单。roipoly在删除顶点的邻居的两个顶点之间画了一条新的直线。
Changing the color of the polygon Move the pointer anywhere inside the boundary of the region and click the right mouse button. SelectSet color从上下文菜单。
Retrieving the coordinates of the vertices 将指针移入区域内。右键单击并选择复制位置从上下文菜单将当前位置复制到剪贴板。该职位是n-b-2阵列包含x- 和y- 每个顶点的坐标,其中nis the number of vertices.

提示

  • roipolyalways produces a closed polygon. If you specify input vertex positions of a closed polygon (such that the last pair of coordinates is identical to the first pair), then the length of the output coordinate vectors is equal to the number of points specified. If the points specified do not describe a closed polygon, thenroipoly添加了一个与第一点相同的坐标的最后点。在这种情况下,输出坐标向量的长度大于指定的点数。

  • For more information about classifying pixels on the ROI boundary, seeClassify Pixels That Are Partially Enclosed by ROI

  • For any of theroipoly语法,您可以替换输入图像Iwith two arguments,mn,指定任意图像的行和列尺寸。例如,这些命令创建一个100 x-200二进制掩码。

    c = [112 112 79 79]; r = [37 66 66 37]; BW = roipoly(100,200,c,r);

    如果指定mn与一个交互式佛rm ofroipoly, anm-经过-n显示黑色图像。使用鼠标在此图像中指定多边形。

Version History

在R2006a之前引入