(Not recommended) Create draggable ellipse
imellipse is not recommended. Use the
object instead. You can also use the ROI creation convenience function
drawellipse. If you used
imellipse to create a
circular ROI, use the
object instead. For more information, see Compatibility Considerations.
imellipse object encapsulates an interactive ellipse
over an image.
You can adjust the size and position of the ellipse by using the mouse. The ellipse also has a context menu that controls aspects of its appearance and behavior. For more information, see Usage.
h = imellipse begins interactive placement of an ellipse
on the current axes, and returns an
h = imellipse( begins
interactive placement of an ellipse on the object specified by
h = imellipse(___,"PositionConstraintFcn",
also specifies where the ellipse can be dragged using a position constraint
hparent — Handle to parent object
Handle to parent object, specified as a handle. The parent is
typically an axes object, but can also be any other object that can be
the parent of an
position — Position of ellipse
Position of the ellipse as defined by a bounding rectangle, specified
as a 4-element vector of the form
[xmin ymin width
height]. The initial size of the bounding rectangle is
height, and the
upper-left corner of the rectangle is at the (x,y) coordinate
fcn — Position constraint function
Position constraint function, specified as a function handle.
fcn is called whenever the mouse is dragged.
You can use this function to control where the ellipse can be dragged.
See the help for the
setPositionConstraintFcn function for information about
valid function handles.
Deletable — ROI can be deleted
true (default) |
ROI can be deleted, specified as
When you call
imellipse with an interactive syntax, the pointer
changes to a cross hairs when over an image. Click and drag the mouse to
specify the size and position of the ellipse. The ellipse also supports a context menu
that you can use to control aspects of its appearance and behavior. Right-click on the
ellipse to access this context menu.
The table lists the interactive behavior supported by
|Moving the entire ellipse.||Move the pointer inside the ellipse. The pointer changes to a fleur shape . Click and drag the mouse to move the ellipse.|
|Resizing the ellipse.||Move the pointer over a resizing handle on the ellipse. The pointer changes to a double-ended arrow shape . Click and drag the mouse to resize the ellipse.|
|Changing the color used to display the ellipse.||Move the pointer inside the ellipse. Right-click and select Set Color from the context menu.|
|Retrieving the current position of the ellipse.||Move the pointer inside the ellipse. Right-click and select
Copy Position from the context menu.
|Preserving the current aspect ratio of the ellipse during resizing.||Move the pointer inside the ellipse. Right-click and select Fix Aspect Ratio from the context menu.|
|Deleting the ellipse||Move the pointer inside the ellipse. Right-click and select
Delete from the context menu. To remove
this option from the context menu, set the |
imellipse object supports a number of methods. Type
methods imellipse to see a complete list.
|Add new-position callback to ROI object|
|(Not recommended) Create mask within image|
|Delete handle object|
|Get color used to draw ROI object|
|Return current position of ROI object|
|Return function handle to current position constraint function|
|Return vertices on perimeter of ellipse ROI object|
|Remove new-position callback from ROI object|
|(Not recommended) Resume execution of MATLAB command line|
|(Not recommended) Set color used to draw ROI object|
|Set ROI object to new position|
|Preserve aspect ratio when resizing ROI object|
|(Not recommended) Move ROI object to new position|
|Set position constraint function of ROI object|
|Set resize behavior of ROI object|
|(Not recommended) Block MATLAB command line until ROI creation is finished|
Update Title when Ellipse Moves
Create an ellipse.
imshow("coins.png") h = imellipse(gca,[10 10 100 100]);
Use callbacks to display the updated position in the title of the figure.
The example illustrates using the
keep the ellipse inside the original
addNewPositionCallback(h,@(p) title(mat2str(p,3))); fcn = makeConstrainToRectFcn("imellipse",get(gca,"XLim"),get(gca,"YLim")); setPositionConstraintFcn(h,fcn);
Click and Drag to Place Ellipse
Interactively place an ellipse by clicking and dragging. Use
block the MATLAB® command line. Double-click on the ellipse to resume execution
of the MATLAB command line.
imshow("coins.png") h = imellipse; position = wait(h);
If you use
imellipse with an axes that contains an image object,
and do not specify a position constraint function, users can drag the ellipse outside
the extent of the image and lose the ellipse. When used with an axes created by the
plot function, the axes limits automatically expand to
accommodate the movement of the ellipse.
Version HistoryIntroduced in R2007b
imellipse is not recommended
Starting in R2018b, a new set of ROI objects replaces the existing set of ROI objects. The new objects provide more functional capabilities, such as face color transparency. The new classes also support events that you can use to respond to changes in your ROI such as moving or being clicked. Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities and flexibility. For more information on creating ROIs using the new ROI functions, see Create ROI Shapes.
Replace use of the
imellipse object with the new
ROI object. You can also use the ROI convenience function
Update all instances of
|Discouraged Usage||Recommended Replacement|
This example creates an ellipse ROI.
imshow("cameraman.tif"); h = imellipse(gca,[10 10 100 150]);
Here is roughly equivalent code, replacing the old ROI
object with the new ROI object. Note that, with the previous
ROIs, you defined an ellipse by the size of the bounding
imshow("cameraman.tif"); h = drawellipse(gca,"Center",[65 90],"Semi",[50 75]);
Update code that uses any of the object functions of the
imellipse ROI object. In many cases, you can replace the
call to an
imellipse object function by simply accessing or
setting the value of an
Ellipse ROI object property. For
example, replace calls to
setColor with use of the
property. In some cases, you must replace the
object function with an object function of the new
ROI. Each of the individual
imellipse ROI object methods
include information about migrating to the new
object. For a migration overview, see ROI Migration.