drawrectangle
创建可自定义的矩形ROI
Description
这drawrectangle
function creates aRectangle
指定矩形区域(ROI)的形状和位置的对象。您可以通过使用鼠标在图像上绘制ROI或使用名称值参数来交互创建ROI。您还可以指定ROI的初始外观和行为。
After you create the ROI, you can use object properties, object functions, and event notifications to customize the shape, position, appearance, and behavior of the ROI. For more information about using these capabilities, seeTips。
creates aroi
= drawrectangleRectangle
对象并启用当前轴上ROI的交互式图。
To draw the ROI, position the pointer on the image. The cursor changes to a fleur shape. Click and drag to draw the rectangular ROI. To finish the ROI, release the mouse button. For more information about using the ROI, including keyboard shortcuts and context menu options, seeTips。
Examples
Draw Nested Rectangular ROIs
Read an image into the workspace and display it.
imshow(imread('baby.jpg'))
Draw a red rectangular ROI with the label'OuterRectangle'
。
r1 = drawRectangle('标签',,,,'OuterRectangle',,,,'Color',[1 0 0]);
绘制另一个矩形ROI,将绘图区域限制在第一个矩形内部的区域。
r2 = drawRectangle('标签',,,,“ innerrectangle',,,,'DrawingArea',,,,r1.Position);
Create Rectangular ROI Programmatically
Read image into the workspace and display it.
I = imread('baby.jpg'); figure imshow(I)
使用命名参数在图像上绘制矩形ROI,以指定矩形的位置和大小。该示例还规定了矩形的边缘是条纹线。
H= drawrectangle('Position',[500,500,1000,1000],'StripeColor',,,,'r');
Set Up Listener for Rectangle ROI Events
Read an image into the workspace.
I = imread('cameraman.tif');
Display the image.
imshow(I);
Draw a rectangular ROI on the image.
roi = drawrectangle('Color',,,,'r');
Set up listeners for ROI moving events. When you move it, the ROI sends notifications of these events and executes the callback function you specify.
addlistener(roi,'MoveRoi',@Pallvents);addlistener(roi,'ROIMoved',@Pallvents);
这缓解
callback function displays the previous position and the current position of the ROI.
function缓解((src,evt) evname = evt.EventName;switch((evname)case{'MoveRoi'} disp(['ROI moving previous position: 'mat2str(evt.PreviousPosition)]); disp([“ ROI移动当前位置”:'mat2str(evt.currentposition)]);case{'ROIMoved'} disp(['ROI moved previous position: 'mat2str(evt.PreviousPosition)]); disp(['ROI moved current position: 'mat2str(evt.currentposition)]);结尾结尾
输入参数
斧头
-Parent of ROI
gca
((default) |Axes
目的|UIAxes
目的
Parent of ROI, specified as anAxes
目的or aUIAxes
目的。For information about using an ROI in a UIAxes, including important limitations, seeUsing ROIs in Apps Created with App Designer。
名称值参数
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
,,,,wHereName
是参数名称和Value
相应的价值。名称-值参数must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and encloseName
in quotes.
Example:'Color','y'
creates a yellow coloredRectangle
目的
AspectRatio
-Aspect ratio of rectangle
非负数
矩形的纵横比,指定为非负数。纵横比定义为高度宽度
。
颜色
-ROI color
[0 0.4470 0.7410]
((default) |RGB triplet|颜色名称|short color name
ROI color, specified as an RGB triplet, a color name, or a short color name.
您可以使用RGB三胞胎指定任何颜色。RGB三重态是一个3元素行矢量,其元素指定颜色的红色,绿色和蓝色组件的强度。强度必须在[0,1]范围内。
您可以按名称指定一些常见的颜色为字符串标量或字符向量。该表列出了命名的颜色选项和等效的RGB三重态。
颜色Name | Short Name | RGB三胞胎 | Appearance |
---|---|---|---|
'红色的' |
'r' |
[1 0 0] |
|
'green' |
'g' |
[0 1 0] |
|
'blue' |
'b' |
[0 0 1] |
|
'cyan' |
'c' |
[0 1 1] |
|
'magenta' |
'm' |
[1 0 1] |
|
'yellow' |
'y' |
[1 1 0] |
|
'black' |
'k' |
[0 0 0] |
|
'白色的' |
'W' |
[1 1 1] |
|
这是MATLAB的默认颜色的RGB三胞胎®uses in many types of plots.
RGB三胞胎 | Appearance |
---|---|
[0 0.4470 0.7410] |
|
[0.8500 0.3250 0.0980] |
|
[0.9290 0.6940 0.1250] |
|
[0.4940 0.1840 0.5560] |
|
[0.4660 0.6740 0.1880] |
|
[0.3010 0.7450 0.9330] |
|
[0.6350 0.0780 0.1840] |
|
Example:“颜色”,'r'
Example:'Color','green'
Example:'Color',[0 0.4470 0.7410]
ContextMenu
-Context menu
ContextMenu
目的
Context menu that displays when you right-click the ROI, specified as aContextMenu
目的。You can create a custom context menu by using theuicontextmenu
function and then configuring context menu properties.
删除
-Context menu provides option to delete the ROI
true
or1
((default) |错误的
or0
Context menu provides an option to delete the ROI, specified asa numeric or logical1
((true
)or0
((错误的
)。当值为true
,,,,you can delete the ROI interactively using the context menu. When the value is错误的
,,,,the context menu option to delete the ROI is disabled.
In both cases, you can delete the ROI outside of the context menu by using thedelete
功能。
DrawingArea
-Area of axes in which you can interactively place ROI
'汽车'
((default) |'unlimited'
|[x,y,w,h]
区域的轴interactively place the ROI, specified as one of the values in this table.
Value | Description |
---|---|
'汽车' |
这drawing area is the current axes limits (default). |
'unlimited' |
这drawing area has no boundary and ROIs can be drawn or dragged to extend beyond the axes limits. |
[x,y,w,h] |
这drawing area is restricted to a rectangular region beginning at (X,,,,y),延伸到宽度wand heightH。 |
facealpha
-Transparency of ROI face
0。2
((default) |数字in the range [0, 1]
ROI面的透明度,指定为[0,1]范围内的数字。当值为1
,ROI的脸完全不透明。当值为0
,,,,the ROI face is completely transparent.
可以面对
-ROI face can capture clicks
true
or1
((default) |错误的
or0
ROI face can capture clicks, specified asa numeric or logical1
((true
)or0
((错误的
)。什么时候true
,,,,the ROI face captures mouse clicks. When错误的
,ROI脸不会捕获鼠标点击。
FixedAspectRatio
-纵横比保持恒定
错误的
or0
((default) |true
or1
纵横比在交互期间保持恒定,指定为a numeric or logical0
((错误的
)or1
((true
)。当值为true
,,,,the aspect ratio remains constant when you draw or resize the ROI. When the value is错误的
,您可以在绘制或调整ROI大小时更改纵横比。
HandleVisibility
-Visibility of ROI handle in孩子们
property of parent
'上'
((default) |'off'
|'打回来'
ROI手柄的可见性孩子们
父的属性,指定为该表中的值之一。
Value | Description |
---|---|
'上' |
这目的Handle is always visible (default). |
'off' |
这目的Handle is hidden at all times. |
'打回来' |
这目的Handle is visible from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line. |
InteractionsAllowed
-Interactivity of ROI
'全部'
((default) |'没有任何'
|'翻译'
Interactivity of the ROI, specified as one of the values in this table.
Value | Description |
---|---|
'全部' |
完全interactable ROI。 |
'没有任何' |
ROI不可交互,也看不到阻力点。 |
'翻译' |
这ROI can be translated (moved) within the drawing area. |
Label
-ROI label
''
((default) |character vector|string scalar
ROI label, specified as a character vector or string scalar. By default, the ROI has no label (''
)。
标签
-文本背景的透明度
1
((default) |数字in the range [0, 1]
Transparency of the text background, specified as a number in the range [0, 1]. When set to1
,文字背景完全不透明。设置为0
,,,,the text background is completely transparent.
LabelTextColor
-Label text color
'black'
((default) |RGB triplet|颜色名称|short color name
Label text color, specified as an RGB triplet, a color name, or a short color name.
您可以使用RGB三胞胎指定任何颜色。RGB三重态是一个3元素行矢量,其元素指定颜色的红色,绿色和蓝色组件的强度。强度必须在[0,1]范围内。
您可以按名称指定一些常见的颜色为字符串标量或字符向量。该表列出了命名的颜色选项和等效的RGB三重态。
颜色Name | Short Name | RGB三胞胎 | Appearance |
---|---|---|---|
'红色的' |
'r' |
[1 0 0] |
|
'green' |
'g' |
[0 1 0] |
|
'blue' |
'b' |
[0 0 1] |
|
'cyan' |
'c' |
[0 1 1] |
|
'magenta' |
'm' |
[1 0 1] |
|
'yellow' |
'y' |
[1 1 0] |
|
'black' |
'k' |
[0 0 0] |
|
'白色的' |
'W' |
[1 1 1] |
|
这是MATLAB的默认颜色的RGB三胞胎uses in many types of plots.
RGB三胞胎 | Appearance |
---|---|
[0 0.4470 0.7410] |
|
[0.8500 0.3250 0.0980] |
|
[0.9290 0.6940 0.1250] |
|
[0.4940 0.1840 0.5560] |
|
[0.4660 0.6740 0.1880] |
|
[0.3010 0.7450 0.9330] |
|
[0.6350 0.0780 0.1840] |
|
Example:“ LabelTextColor','r'
Example:“ LabelTextColor”,“绿色”
Example:“ LabelTextColor”,[0 0.4470 0.7410]
LabelVisible
-Visibility of ROI label
'上'
((default) |'hover'
|'inside'
|'off'
ROI标签的可见性,指定为这些值之一。
Value | Description |
---|---|
'上' |
Label is visible when the ROI is visible, and theLabel 属性是非空的(默认)。 |
'hover' |
仅当小鼠徘徊在ROI上时,才能看到标签。 |
'inside' |
Label is visible only when there is adequate space inside the ROI to display it. |
'off' |
Label is not visible. |
LineWidth
-Width of ROI border
positive number
Width of the ROI border, specified as a positive number in points. The default value is three times the number of points per screen pixel, such that the border is three pixels wide.
MarkerSize
-Marker size
positive number
Marker size, specified as a positive number in points. The default value is eight times the number of points per screen pixel, such that markers are eight pixels in size.
Parent
-ROI父母
Axes
目的|UIAxes
目的
ROI父母,,,,specified as anAxes
orUIAxes
目的。For information about using an ROI in a UIAxes, including important limitations, seeUsing ROIs in Apps Created with App Designer。
位置
-ROI的位置
1-by-4 numeric vector
ROI的位置,指定为表格的1 x-4数字向量[Xmin,,,,ymin,,,,width,,,,Height].Xminandyminspecify the coordinates of the upper left corner of the rectangle.widthandHeightspecify the width and height of the rectangle and must be nonnegative.
可旋转
-Ability of ROI to be rotated
错误的
or0
((default) |true
or1
Ability of the ROI to be rotated, specified asa numeric or logical0
((错误的
)or1
((true
)。当值为true
,,,,you can rotate the rectangle by clicking near the markers at the corners. When the value is错误的
,您不能旋转矩形。
RotationAngle
-Rotation angle
0
((default) |数字
Rotation angle of the ROI, specified as a number. The angle is measured in degrees in a clockwise direction around the center of the ROI.
选定
-Selection state of ROI
错误的
or0
((default) |true
or1
Selection state of the ROI, specified asa numeric or logical0
((错误的
)or1
((true
)。
选定颜色
-选择ROI的颜色
'没有任何'
((default) |RGB triplet|颜色名称|short color name
颜色of the ROI when selected, specified as an RGB triplet, a color name, a short color name, or'没有任何'
。If you specify'没有任何'
,然后的价值颜色
定义所有状态的ROI的颜色,无论是否选择。
您可以使用RGB三胞胎指定任何颜色。RGB三重态是一个3元素行矢量,其元素指定颜色的红色,绿色和蓝色组件的强度。强度必须在[0,1]范围内。
您可以按名称指定一些常见的颜色为字符串标量或字符向量。该表列出了命名的颜色选项和等效的RGB三重态。
颜色Name | Short Name | RGB三胞胎 | Appearance |
---|---|---|---|
'红色的' |
'r' |
[1 0 0] |
|
'green' |
'g' |
[0 1 0] |
|
'blue' |
'b' |
[0 0 1] |
|
'cyan' |
'c' |
[0 1 1] |
|
'magenta' |
'm' |
[1 0 1] |
|
'yellow' |
'y' |
[1 1 0] |
|
'black' |
'k' |
[0 0 0] |
|
'白色的' |
'W' |
[1 1 1] |
|
这是MATLAB的默认颜色的RGB三胞胎uses in many types of plots.
RGB三胞胎 | Appearance |
---|---|
[0 0.4470 0.7410] |
|
[0.8500 0.3250 0.0980] |
|
[0.9290 0.6940 0.1250] |
|
[0.4940 0.1840 0.5560] |
|
[0.4660 0.6740 0.1880] |
|
[0.3010 0.7450 0.9330] |
|
[0.6350 0.0780 0.1840] |
|
Example:'SelectedColor','r'
Example:'SelectedColor','green'
Example:“ Selected Color”,[0 0.4470 0.7410]
脱衣舞
-颜色of ROI stripe
'没有任何'
((default) |RGB triplet|颜色名称|short color name
颜色of the ROI stripe, specified as an RGB triplet, a color name, a short color name, or'没有任何'
。If you specify'没有任何'
,然后ROI边缘是由固体颜色指定的颜色
。Otherwise, the edge of the ROI is striped, with colors alternating between the colors specified by颜色
and脱衣舞
。
您可以使用RGB三胞胎指定任何颜色。RGB三重态是一个3元素行矢量,其元素指定颜色的红色,绿色和蓝色组件的强度。强度必须在[0,1]范围内。
您可以按名称指定一些常见的颜色为字符串标量或字符向量。该表列出了命名的颜色选项和等效的RGB三重态。
颜色Name | Short Name | RGB三胞胎 | Appearance |
---|---|---|---|
'红色的' |
'r' |
[1 0 0] |
|
'green' |
'g' |
[0 1 0] |
|
'blue' |
'b' |
[0 0 1] |
|
'cyan' |
'c' |
[0 1 1] |
|
'magenta' |
'm' |
[1 0 1] |
|
'yellow' |
'y' |
[1 1 0] |
|
'black' |
'k' |
[0 0 0] |
|
'白色的' |
'W' |
[1 1 1] |
|
这是MATLAB的默认颜色的RGB三胞胎uses in many types of plots.
RGB三胞胎 | Appearance |
---|---|
[0 0.4470 0.7410] |
|
[0.8500 0.3250 0.0980] |
|
[0.9290 0.6940 0.1250] |
|
[0.4940 0.1840 0.5560] |
|
[0.4660 0.6740 0.1880] |
|
[0.3010 0.7450 0.9330] |
|
[0.6350 0.0780 0.1840] |
|
Example:'StripeColor','r'
Example:'StripeColor','green'
Example:'StripeColor',[0 0.4470 0.7410]
Tag
-Tag to associate with ROI
''
((default) |character vector|string scalar
Tag to associate with the ROI, specified as a character vector or string scalar. Use the tag value to find the ROI object in a hierarchy of objects using thefindobj
功能。
UserData
-Data to associate with ROI
any MATLAB data
Data to associate with the ROI, specified as any MATLAB data. For example, you can specify a scalar, vector, matrix, cell array, string, character array, table, or structure. Thedrawrectangle
目的does not use this data.
Visible
-ROI visibility
'上'
((default) |'off'
|on/off logical value
ROI可见性,指定为'上'
or'off'
,或作为数字或逻辑1
((true
)or0
((错误的
)。A value of'上'
is equivalent to true, and'off'
is equivalent to false. The value is stored as an on/off logical value of typeOnOffSwitchState
。
Value | Description |
---|---|
'上' |
显示ROI。 |
'off' |
Hide the ROI without deleting it. You still can access the properties of an invisible ROI. |
Output Arguments
roi
- 矩形ROI
Rectangle
目的
Rectangular ROI, returned as aRectangle
目的。
Tips
这ROI supports the following interactivity, including keyboard shortcuts.
Behavior Keyboard shortcut Cancel drawing the ROI. 按Esc。这function returns a valid ROI object with an empty 位置
财产。Resize (reshape) the ROI. 将指针定位在顶点上,然后单击并拖动。矩形在每个角和每一侧的中点都有顶点。为了在调整大小时保持纵横比,请按转移key. To lock the aspect ratio, use the修复长宽比in the right-click context menu.
Move the ROI. 位置the pointer over the ROI. The pointer changes to the fleur shape. Click and drag the ROI. Delete the ROI. 位置the pointer anywhere on the ROI and right-click. SelectDelete Rectangle从上下文菜单。您也可以使用 delete
功能。这
drawrectangle
function creates aRectangle
目的。After you create the object, you can modify the shape, position, appearance, and behavior of the ROI by using these object capabilities.能力 万博1manbetx Object properties ROI对象具有指定其形状,位置,外观和行为的属性。创建ROI对象后,使用点表示法更改属性。
For example, to change the color of the
roi
to yellow, set its颜色
property:ROI.Color ='yellow'
Object functions ROI objects have object functions that operate on the ROIs. For example, if you want to pause the MATLAB command line after creating an ROI, use the wait
功能。事件通知 ROI objects can notify your code when certain events occur, such as when the ROI is clicked or when the ROI is being moved. To receive event notifications, set uplisteners。什么时候the ROI notifies your application through the listener, it returns data specific to the event. For example, with the
ROIMoved
event, the ROI object returns its previous position and its current position. You can specify a callback function that executes when an event occurs.For an example of using event listeners with the
Rectangle
目的,,,,seeSet Up Listener for Rectangle ROI Events。
版本历史记录
在R2018B中引入R2020a:Uicontextmenu
不建议使用名称值参数
Not recommended starting in R2020a
Starting in R2020a, using theUicontextmenu
name-value argument to assign a context menu to an ROI object is not recommended. Use theContextMenu
name-value argument instead. The values are the same.
这re are no plans to remove support for theUicontextmenu
此时的名称值参数。
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
您单击了与此MATLAB命令相对应的链接:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
Americas
- América Latina((Español)
- Canada((English)
- United States((English)
Europe
- Belgium((English)
- Denmark((English)
- Deutschland((Deutsch)
- España((Español)
- 芬兰((English)
- France(Français)
- Ireland((English)
- Italia(意大利语)
- Luxembourg((English)
- Netherlands((English)
- Norway((English)
- Österreich((Deutsch)
- 葡萄牙((English)
- Sweden((English)
- Switzerland
- United Kingdom((English)