Main Content

imellipse

(Not recommended) Create draggable ellipse

imellipse is not recommended. Use the Ellipse ROI object instead. You can also use the ROI creation convenience function drawellipse. If you used imellipse to create a circular ROI, use the Circle ROI object instead. For more information, see Version History.

Description

An 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.

Creation

Description

h = imellipse begins interactive placement of an ellipse on the current axes, and returns an imellipse object.

h = imellipse(hparent) begins interactive placement of an ellipse on the object specified by hparent.

h = imellipse(hparent,position) creates a draggable ellipse at the position position on the object specified by hparent.

example

h = imellipse(___,"PositionConstraintFcn",fcn) also specifies where the ellipse can be dragged using a position constraint function, fcn.

Input Arguments

expand all

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 hggroup object.

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 width-by-height, and the upper-left corner of the rectangle is at the (x,y) coordinate (xmin,ymin).

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.

Properties

expand all

ROI can be deleted, specified as true or false.

Data Types: logical

Usage

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.

Blue ellipse displayed over an image, with draggable points to resize the ellipse and a context menu that gives options to copy the position, set the color, fix the aspect ratio, or delete the ellipse.

The table lists the interactive behavior supported by imellipse.

Interactive BehaviorDescription
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. imellipse copies a four-element position vector [xmin ymin width height] to the clipboard.
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 ellipseMove the pointer inside the ellipse. Right-click and select Delete from the context menu. To remove this option from the context menu, set the Deletable property to false: h = imellipse(); h.Deletable = false;

Object Functions

Each imellipse object supports a number of methods. Type methods imellipse to see a complete list.

addNewPositionCallbackAdd new-position callback to ROI object
createMask(Not recommended) Create mask within image
deleteDelete handle object
getColorGet color used to draw ROI object
getPositionReturn current position of ROI object
getPositionConstraintFcnReturn function handle to current position constraint function
getVerticesReturn vertices on perimeter of ellipse ROI object
removeNewPositionCallbackRemove new-position callback from ROI object
resume(Not recommended) Resume execution of MATLAB command line
setColor(Not recommended) Set color used to draw ROI object
setConstrainedPositionSet ROI object to new position
setFixedAspectRatioModePreserve aspect ratio when resizing ROI object
setPosition(Not recommended) Move ROI object to new position
setPositionConstraintFcnSet position constraint function of ROI object
setResizableSet resize behavior of ROI object
wait(Not recommended) Block MATLAB command line until ROI creation is finished

Examples

collapse all

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 makeConstrainToRectFcn to keep the ellipse inside the original XLim and YLim ranges.

addNewPositionCallback(h,@(p) title(mat2str(p,3)));
fcn = makeConstrainToRectFcn("imellipse",get(gca,"XLim"),get(gca,"YLim"));
setPositionConstraintFcn(h,fcn);

Interactively place an ellipse by clicking and dragging. Use wait to 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);

Tips

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 History

Introduced in R2007b

collapse all

R2018b: 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 Ellipse ROI object. You can also use the ROI convenience function drawellipse.

Update ROI Creation Code

Update all instances of imellipse.

Discouraged UsageRecommended 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 rectangle, [x,y,width,height]. With the new ROIs, you define an ellipse by specifying the center point of the ellipse and the length of the semi-major and semi-minor axes.

imshow("cameraman.tif");
h = drawellipse(gca,"Center",[65 90],"Semi",[50 75]);
Other ROI Code Updates

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 getColor or setColor with use of the Color property. In some cases, you must replace the imellipse object function with an object function of the new Ellipse ROI. Each of the individual imellipse ROI object methods include information about migrating to the new Ellipse ROI object. For a migration overview, see ROI Migration.