Crosshair

Crosshair region of interest

Description

The Crosshair object is a crosshair region-of-interest (ROI).

To draw the ROI, position the cursor over the image and click the mouse to draw the ROI. For more information about using this ROI, including keyboard shortcuts, see Tips.

Creation

Description

To create a Crosshair object, use the images.roi.Crosshair creation function. After creating the object, call the draw object function to begin drawing the ROI. As a convenience, you can also use the drawcrosshair function to create a Crosshair object. The drawcrosshair function creates the ROI object and automatically calls the draw object function.

example

roi = images.roi.Crosshair creates a Crosshair object with default properties.

roi = images.roi.Crosshair(ax) creates the ROI in the axes specified by ax.

roi = images.roi.Crosshair(___,Name,Value) sets properties using one or more name-value pairs. For example, images.roi.Crosshair('Color','y') sets the color of the crosshair ROI to yellow. Enclose each property name in quotes.

Input Arguments

expand all

Parent of ROI, specified as an Axes object or a UIAxes object. For information about using an ROI in a UIAxes, including important limitations, see Using ROIs in Apps Created with App Designer.

Properties

expand all

ROI color, specified as a MATLAB® ColorSpec (Color Specification).

Example: 'green'

Example: 'g'

Example: [0 1 0]

ROI can be interactively deleted via a context menu, specified as true or false. When the value is true (default), you can delete the ROI via the context menu. To disable this context menu item, set this property to false. When the value is set to false, you can still delete the ROI by calling the delete function specifying the handle to the ROI as the input.

Area of the axes in which you can interactively place the ROI, specified as one of the values in this table.

ValueDescription
'auto'The drawing area is the current axes limits (default).
'unlimited'The drawing area has no boundary and ROIs can be drawn or dragged to extend beyond the axes limits.
[x,y,w,h]The drawing area is restricted to a rectangular region beginning at (x,y), and extending to width w and height h.

Visibility of the ROI handle in the Children property of the parent, specified as one of the values in this table.

ValueDescription
'on'The object handle is always visible (default).
'off'The object handle is hidden at all times.
'callback' The object handle is visible from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line.

Interactivity of the ROI, specified as one of the values in this table.

ValueDescription
'all'The ROI is fully interactable (default).
'none'The ROI is not interactable, and no drag points are visible.

ROI label, specified as a character vector or string. By default, the ROI has no label ('').

Visibility of the ROI label, specified as one of these values:

ValueDescription
'on'Label is visible when the ROI is visible and the Label property is nonempty (default).
'hover'Label is visible only when the mouse hovers over the ROI.
'off'Label is not visible.

Width of the ROI edge, specified as a positive numeric scalar in points. The default value is three times the number of points per screen pixel.

ROI parent, specified as an Axes or UIAxes object. For information about using an ROI in a UIAxes, including important limitations, see Using ROIs in Apps Created with App Designer.

Position of the ROI, specified as a 1-by-2 numeric array of the form [x y]. The values x and y specify the x- and y-coordinates of the location where the horizontal line crosses the vertical line in the crosshair ROI. This value changes automatically when you draw or move the ROI.

Selection state of the ROI, specified as the logical value true or false. You can also set this property interactively. For example, clicking on the ROI selects the ROI and sets this property to true. Similarly, pressing the Ctrl key and clicking the ROI deselects the ROI and sets the value of this property to false.

Color of the ROI when selected, specified as a MATLAB ColorSpec (Color Specification). The intensities must be in the range [0,1]. If 'SelectedColor' is set to 'none', then the value of Color defines the color of the ROI for all states, selected or not.

Example: 'green'

Example: 'g'

Example: [0 1 0]

Color of the ROI stripe, specified as a MATLAB ColorSpec (Color Specification) value. By default, the edge of an ROI is solid colored. If you specify StripeColor, the ROI edge is striped. The striping consists of a combination of the value specified by 'Color' and this value.

Example: 'green'

Example: 'g'

Example: [0 1 0]

Tag to associate with the ROI, specified as a character vector or string. Use the tag value to find the ROI object in a hierarchy of objects using the findobj function.

Context menu, specified as a ContextMenu object. Use this property to display a custom context menu when you right-click the ROI. You can create a custom context menu by using the uicontextmenu function and then configuring context menu properties.

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. MATLAB does not use this data.

ROI visibility, specified as one of the values in this table.

ValueDescription
'on'Display the ROI (default).
'off'Hide the ROI without deleting it. You still can access the properties of an invisible ROI.

Object Functions

addlistenerCreate event listener bound to event source
beginDrawingFromPointBegin drawing ROI from specified point
bringToFrontBring ROI to front of Axes stacking order
drawBegin drawing ROI interactively
waitBlock MATLAB command line until ROI operation is finished

Examples

collapse all

Read an image into the workspace and display it.

I = imread('baby.jpg');
figure;
imshow(I)

Place a crosshair ROI on the image programmatically. When you specify the position of the ROI, you must specify the axes.

h = images.roi.Crosshair(gca,'Position',[100,100]);

Read an image into the workspace.

img = imread('coins.png');

Display the image in a figure.

hAx = gca;
imObj = imshow(img,'Parent',hAx);
imObj.Parent.Visible = 'on';

Create a crosshair ROI on the image.

h = images.roi.Crosshair('Parent',hAx,'Position',[50 50],'LineWidth',1,'Color','y');

Set up a listener to get notification when the ROI moves over the image. Because the code displays the value of the pixel under the crosshair, you must pass the image as an argument to the listener.

addlistener(h,'MovingROI',@(src,data)displayInfo(src,data,hAx,img));

Define the displayInfo function called by the listener when a 'MovingROI' event occurs.

function displayInfo(~,data,hAx,img)
pos = ceil(data.CurrentPosition);
title(hAx,['Pixel Value: ',num2str(img(pos(2),pos(1)))])
end

Appearance of the image with title during interactive movement of the Crosshair ROI.

More About

expand all

Tips

  • This table describes how to perform common tasks with the Crosshair ROI.

    TaskDescription
    Cancel drawing operation.Press Esc. The function returns a valid ROI object with an empty Position field.
    Move the ROI.Position the cursor over the center of the crosshair ROI (where the two lines cross) and click and drag the crosshair. Another way to move the crosshair ROI is to position the cursor anywhere on one of the two lines and click. The other line in the crosshair jumps to the new crosshair center position.
    Delete the ROI.Position the cursor over the ROI, right-click, and then choose Delete Crosshair from the context menu. You can also delete the ROI programmatically by using the delete object function.
  • For information about using an ROI in an app created with App Designer, see Using ROIs in Apps Created with App Designer.

Introduced in R2019b