Documentation

Image Properties

Control image appearance and behavior

Image properties control the appearance and behavior of image objects. By changing property values, you can modify certain aspects of the image.

Starting in R2014b, you can use dot notation to refer to a particular object and property:

h = image(rand(20));
c = h.CData;
h.CDataMapping = 'scaled';

If you are using an earlier release, use the get and set functions to query and set properties.

Image Data

expand all

CDataImage color data64-by-64 array (default) | vector or matrix | 3-D array of RGB triplets

Image color data, specified in one of these forms:

  • Vector or matrix — Each element defines an indexed color for one rectangular area of the image. The elements map to colors in the colormap. The CDataMapping property controls the mapping method.

  • 3-D array of RGB triplets — Each RGB triplet defines a true color for one rectangular area of the image. An RGB triplet is a three-element vector that specifies the intensities of the red, green, and blue components of the color. The first page of the 3-D array contains the red components, the second page contains the green components, and the third page contains the blue components. Since the image uses true colors instead of colormap colors, the CDataMapping property has no effect.

    • If CData is of type double, then an RGB triplet value of [0 0 0] corresponds to black and [1 1 1] corresponds to white.

    • If CData is an integer type, then the image uses the full range of data to determine the color. For example, if CData is of type uint8, then [0 0 0] corresponds to black and [255 255 255] corresponds to white. If CData is of type int8, then [-255 -255 -255] corresponds to black and [255 255 255] corresponds to white.

    • If CData is of type logical, then [0 0 0] corresponds to black and [1 1 1] corresponds to white.

This illustration shows the relative dimensions of CData for the two color models.

The behavior of NaN elements is not defined.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

CDataMappingColor data mapping method'direct' (default) | 'scaled'

Color data mapping method, specified as 'direct' or 'scaled'. Use this property to control the mapping of color data values in CData into the colormap. CData must be a vector or a matrix defining indexed colors. This property has no effect if CData is a 3-D array defining true colors.

The methods have these effects:

  • 'direct' — Interpret the values as indices into the current colormap. Values with a decimal portion are fixed to the nearest lower integer.

    • If the values are of type double or single, then values of 1 or less map to the first color in the colormap. Values equal to or greater than the length of the colormap map to the last color in the colormap.

    • If the values are of type uint8, uint16, uint32, uint64 , int8, int16, int32, or int64, then values of 0 or less map to the first color in the colormap. Values equal to or greater than the length of the colormap map to the last color in the colormap (or up to the range limits of the type).

    • If the values are of type logical, then values of 0 map to the first color in the colormap and values of 1 map to the second color in the colormap.

  • 'scaled' — Scale the values to range between the minimum and maximum color limits. The CLim property of the axes contains the color limits.

Image Position

expand all

XDataPlacement along x-axis[1 size(CData,2)] (default) | two-element vector | scalar

Placement along the x-axis, specified in one of these forms:

  • Two-element vector — Use the first element as the location for the center of CData(1,1) and the second element as the location for the center of CData(m,n), where [m,n] = size(CData). Evenly distribute the centers of the remaining CData elements between those two points.

    The width of each CData element is determined by the expression:

    (XData(2)-XData(1))/(size(CData,2)-1)
  • Scalar — Center CData(1,1) at this location and each following element one unit apart.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

YDataPlacement along y-axis[1 size(CData,1)] (default) | two-element vector | scalar

Placement along y-axis, specified in one of these forms:

  • Two-element vector — Use the first element as the location for the center of CData(1,1) and the second element as the location for the center of CData(m,n), where [m,n] = size(CData). Evenly distribute the centers of the remaining CData elements between those two points.

    The height of each CData element is determined by the expression:

    (YData(2)-YData(1))/(size(CData,1)-1)
  • Scalar — Center CData(1,1) at this location and each following element one unit apart.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Image Transparency

expand all

AlphaDataTransparency data1 (default) | scalar | array the same size as CData

Transparency data, specified in one of these forms:

  • Scalar — Use a consistent transparency across the entire image.

  • Array the same size as CData — Use a different transparency value for each image element.

The AlphaDataMapping property controls the mapping of the transparency data values into the figure alphamap.

Example: 0.5

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

AlphaDataMappingTransparency data mapping method'none' (default) | 'scaled' | 'direct'

Transparency data mapping method, specified as 'none', 'scaled', or 'direct'. Use this property to control the mapping of transparency values in AlphaData into the figure alphamap.

The methods have these effects:

  • 'none' — Clamp the values to the region between 0 and 1. A value of 1 or greater is completely opaque, a value of 0 or less is completely transparent, and a value between 0 and 1 is semitransparent.

  • 'scaled' — Scale the values to range between the minimum and maximum alpha limits of the axes. The ALim property of the axes contains the alpha limits.

  • 'direct' — Interpret the values as indices into the figure alphamap. The Alphamap property of the figure contains the alphamap. Values with a decimal portion are fixed to the nearest lower integer.

    • If the values are of type double or single, then values of 1 or less map to the first element in the alphamap. Values equal to or greater than the length of the alphamap are mapped to the last element in the alphamap.

    • If the values are of type uint8, uint16, uint32, uint64 , int8, int16, int32, or int64 then values of 0 or less map to the first element in the alphamap. Values equal to or greater than the length of the alphamap are mapped to the last element in the alphamap (or up to the range limits of the type).

    • If the values are of type logical, then values of 0 map to the first element in the alphamap and values of 1 map to the second element in the alphamap.

Visibility

expand all

VisibleVisibility of image'on' (default) | 'off'

Visibility of image, specified as one of these values:

  • 'on' — Display the image.

  • 'off' — Hide the image without deleting it. You still can access the properties of an invisible image object.

ClippingClipping of image to axes limits'on' (default) | 'off'

Clipping of image to the axes limits, specified as one of these values:

  • 'on' — Do not display parts of the image that are outside the axes limits.

  • 'off' — Display the entire image, even if parts of it appear outside the axes limits. Parts of the image might appear outside the axes limits if you create a plot, set hold on, freeze the axis scaling, and then create the image that is larger than the original plot.

Identifiers

expand all

TypeType of graphics object'image'

This property is read only.

Type of graphics object, returned as the string 'image'.

TagTag to associate with image'' (default) | string

Tag to associate with the image, specified as a string. Tags provide a way to identify graphics objects. Use this property to find all objects with a specific tag within a plotting hierarchy, for example, searching for the tag using findobj.

Example: 'January Data'

UserDataData to associate with image[] (default) | scalar, vector, or matrix | cell array | character array | table | structure

Data to associate with the image object, specified as a scalar, vector, matrix, cell array, character array, table, or structure. MATLAB® does not use this data.

To associate multiple sets of data or to attach a field name to the data, use the getappdata and setappdata functions.

Example: 1:100

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | struct | table | cell

DisplayName(unused) Legend text description'' (default) | string

    Note:   The behavior of the DisplayName property changed in R2014b, and it is not recommended. Image objects do not used this property since legends do not include image objects. This property might be removed in a future release.

Annotation(unused) Legend icon display styleannotation object

    Note:   The behavior of the Annotation property changed in R2014b, and it is not recommended. Image objects do not use this property since legends do not include image objects. This property might be removed in a future release.

Parent/Child

expand all

ParentParent of imageaxes object | group object | transform object

Parent of image, specified as an axes, group, or transform object.

ChildrenChildren of imageempty GraphicsPlaceholder array

The image has no children. You cannot set this property.

HandleVisibilityVisibility of object handle'on' (default) | 'off' | 'callback'

Visibility of object handle in the Children property of the parent, specified as one of these values:

  • 'on' — List the image object.

  • 'off' — Do not list the image object. Use this option to hide object handles when a callback invokes a function that could damage the GUI, such as evaluating a user-typed string.

  • 'callback' — List the image object in the Children property of the parent from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line. Use this option to protect a GUI from command-line users, while allowing callbacks to have access to objects.

If the image object is not listed in the Children property of the parent, then functions that obtain object handles by searching the object hierarchy or querying handle properties cannot return it. This includes get, findobj, gca, gcf, gco, newplot, cla, clf, and close.

Hidden object handles are still valid. Set the root ShowHiddenHandles property to 'on' to list all object handles regardless of their HandleVisibility property setting.

Interactive Control

expand all

ButtonDownFcnMouse-click callback'' (default) | function handle | cell array | string

Mouse-click callback, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • String that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code when you click the image. If you specify this property using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • The image object — You can access properties of the image object from within the callback function.

  • Event data — This argument is empty for this property. Replace it with the tilde character (~) in the function definition to indicate that this argument is not used.

For more information on how to use function handles to define callback functions, see Callback Definition.

    Note:   If the PickableParts property is set to 'none' or if the HitTest property is set to 'off', then this callback does not execute.

Example: @myCallback

Example: {@myCallback,arg3}

UIContextMenuContext menuuicontextmenu object

Context menu, specified as a uicontextmenu object. Use this property to display a context menu when you right-click the image. Create the context menu using the uicontextmenu function.

    Note:   If the PickableParts property is set to 'none' or if the HitTest property is set to 'off', then the context menu does not appear.

SelectedSelection state'off' (default) | 'on'

Selection state, specified as one of these values:

  • 'on' — Selected. If you click the image when in plot edit mode, then MATLAB sets its Selected property to 'on'. If the SelectionHighlight property also is set to 'on', then MATLAB displays selection handles around the image.

  • 'off' — Not selected.

SelectionHighlightDisplay of selection handles when selected'on' (default) | 'off'

Display of selection handles when selected, specified as one of these values:

  • 'on' — Display selection handles when the Selected property is set to 'on'.

  • 'off' — Never display selection handles, even when the Selected property is set to 'on'.

Callback Execution Control

expand all

PickablePartsAbility to capture mouse clicks'visible' (default) | 'none'

Ability to capture mouse clicks, specified as one of these values:

  • 'visible' — Can capture mouse clicks only when visible. The Visible property must be set to 'on'. The HitTest property determines if the image responds to the click or if an ancestor does.

  • 'none' — Cannot capture mouse clicks. Clicking the image passes the click to the object below it in the current view of the figure window. The HitTest property of the image has no effect.

HitTestResponse to captured mouse clicks'on' (default) | 'off'

Response to captured mouse clicks, specified as one of these values:

  • 'on' — Trigger the ButtonDownFcn callback of the image. If you have defined the UIContextMenu property, then invoke the context menu.

  • 'off' — Trigger the callbacks for the nearest ancestor of the image that has a HitTest property set to 'on' and a PickableParts property value that enables the ancestor to capture mouse clicks.

    Note:   The PickableParts property determines if the image object can capture mouse clicks. If it cannot, then the HitTest property has no effect.

InterruptibleCallback interruption'on' (default) | 'off'

Callback interruption, specified as 'on' or 'off'. The Interruptible property determines if a running callback can be interrupted.

    Note:   There are two callback states to consider:

    • The running callback is the currently executing callback.

    • The interrupting callback is a callback that tries to interrupt the running callback.

    Whenever MATLAB invokes a callback, that callback attempts to interrupt a running callback. The Interruptible property of the object owning the running callback determines if interruption is allowed. If interruption is not allowed, then the BusyAction property of the object owning the interrupting callback determines if it is discarded or put in the queue.

If the ButtonDownFcn callback of the image is the running callback, then the Interruptible property determines if it another callback can interrupt it:

  • 'on' — Interruptible. Interruption occurs at the next point where MATLAB processes the queue, such as when there is a drawnow, figure, getframe, waitfor, or pause command.

    • If the running callback contains one of these commands, then MATLAB stops the execution of the callback at this point and executes the interrupting callback. MATLAB resumes executing the running callback when the interrupting callback completes. For more information, see Interrupt Callback Execution.

    • If the running callback does not contain one of these commands, then MATLAB finishes executing the callback without interruption.

  • 'off' — Not interruptible. MATLAB finishes executing the running callback without any interruptions.

BusyActionCallback queuing'queue' (default) | 'cancel'

Callback queuing specified as 'queue' or 'cancel'. The BusyAction property determines how MATLAB handles the execution of interrupting callbacks.

    Note:   There are two callback states to consider:

    • The running callback is the currently executing callback.

    • The interrupting callback is a callback that tries to interrupt the running callback.

    Whenever MATLAB invokes a callback, that callback attempts to interrupt a running callback. The Interruptible property of the object owning the running callback determines if interruption is allowed. If interruption is not allowed, then the BusyAction property of the object owning the interrupting callback determines if it is discarded or put in the queue.

If the ButtonDownFcn callback of the image tries to interrupt a running callback that cannot be interrupted, then the BusyAction property determines if it is discarded or put in the queue. Specify the BusyAction property as one of these values:

  • 'queue' — Put the interrupting callback in a queue to be processed after the running callback finishes execution. This is the default behavior.

  • 'cancel' — Discard the interrupting callback.

Creation and Deletion Control

expand all

CreateFcnCreation callback'' (default) | function handle | cell array | string

Creation callback, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • String that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code when you create the image. Setting the CreateFcn property on an existing image has no effect. You must define a default value for this property, or define this property using a Name,Value pair during image creation. MATLAB executes the callback after creating the image and setting all of its properties.

If you specify this callback using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • The image object — You can access properties of the image object from within the callback function. You also can access the image object through the CallbackObject property of the root, which can be queried using the gcbo function.

  • Event data — This argument is empty for this property. Replace it with the tilde character (~) in the function definition to indicate that this argument is not used.

For more information on how to use function handles to define callback functions, see Callback Definition.

Example: @myCallback

Example: {@myCallback,arg3}

DeleteFcnDeletion callback'' (default) | function handle | cell array | string

Deletion callback, specified as one of these values:

  • Function handle

  • Cell array containing a function handle and additional arguments

  • String that is a valid MATLAB command or function, which is evaluated in the base workspace (not recommended)

Use this property to execute code when you delete the image. MATLAB executes the callback before destroying the image so that the callback can access its property values.

If you specify this callback using a function handle, then MATLAB passes two arguments to the callback function when executing the callback:

  • The image object — You can access properties of the image object from within the callback function. You also can access the image object through the CallbackObject property of the root, which can be queried using the gcbo function.

  • Event data — This argument is empty for this property. Replace it with the tilde character (~) in the function definition to indicate that this argument is not used.

For more information on how to use function handles to define callback functions, see Callback Definition.

Example: @myCallback

Example: {@myCallback,arg3}

BeingDeletedDeletion status of image'off' (default) | 'on'

This property is read only.

Deletion status of image, returned as 'on' or 'off'. MATLAB sets the BeingDeleted property to 'on' when the delete function of the image begins execution (see the DeleteFcn property). The BeingDeleted property remains set to 'on' until the image no longer exists.

Check the value of the BeingDeleted property to verify that the image is not about to be deleted before querying or modifying it.

Was this topic helpful?