This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Package: images.roi

Begin drawing ROI from specified point


beginDrawingFromPoint(ROI,[x y])



beginDrawingFromPoint(ROI,[x y]) enters interactive mode to draw the shape for object ROI starting at location (x,y) in the axes. This method is intended to be used within the ButtonDownFcn callback of an Image or Axes object.


collapse all

Create a new script called sampleDrawLine.m. Inside the script, copy and paste this code, then save the file.

hIm = imshow(imread('coins.png'));
hIm.ButtonDownFcn = @(~,~) buttonPressedCallback(hIm.Parent);
function buttonPressedCallback(hAx)
    cp = hAx.CurrentPoint;
    cp = [cp(1,1) cp(1,2)];
    obj = images.roi.Line('Parent',hAx,'Color',rand([1,3]));

Return to the MATLAB® command window. Run the script by entering the command:


An image of coins is displayed in a figure window. Each time you click the mouse over the figure, the script executes the callback function, buttonPressedCallback. The script begins drawing a new ROI starting from the pixel you clicked.

Input Arguments

collapse all

Starting point in the axes, specified as a numeric array.

Introduced in R2018b