MATLAB Function Reference | Search  Help Desk |
image |
image(C) image(x,y,C) image(...,'PropertyName',PropertyValue,...) image('PropertyName',PropertyValue,...) Formal synatx - PN/PV only handle = image(...)
image
creates an Image graphics object by interpreting each element in a matrix as an index into the Figure's colormap or directly as RGB values, depending on the data specified.
The image
function has two forms:
newplot
to determine where to draw the graphics objects and sets the following Axes properties:
XLim
and YLim
to enclose the Image
Layer
to top
to place the Image in front of the tick marks and grid lines
set
and get
reference pages for examples of how to specify these data types).
image(C)
displays matrix C
as an Image. Each element of C
specifies the color of a rectangular segment in the Image.
image(x,y,C)
where x
and y
are two-element vectors, specifies the range of the x- and y-axis labels, but produces the same Image as image(C)
. This can be useful, for example, if you want the axis tick labels to correspond to real physical dimensions represented by the image.
image(x,y,C,'PropertyName',PropertyValue,...)
is a high-level function that also specifies property name/property value pairs. This syntax calls newplot
before drawing the Image.
image('PropertyName',PropertyValue,...)
is the low-level syntax of the image
function. It specifies only property name/property value pairs as input arguments.
handle = image(...)
returns the handle of the Image object it creates. You can obtain the handle with all forms of the image
function.
Image data can be either indexed or true color. An indexed image stores colors as an array of indices into the Figure colormap. A true color image does not use a colormap; instead, the color values for each pixel are stored directly as RGB triplets. In MATLAB , the CData
property of a truecolor Image object is a three-dimensional (m
-by-n
-by-3) array. This array consists of three m
-by-n
matrices (representing the red, green, and blue color planes) concatenated along the third dimension.
The imread
function reads image data into MATLAB arrays from graphics files in various standard formats, such as TIFF. You can write MATLAB image data to graphics files using the imwrite
function. imread
and imwrite
both support a variety of graphics file formats and compression schemes.
When you read image data into MATLAB using imread
, the data is stored as an array of 8-bit integers. This is a much more efficient storage method than the double-precision (64-bit) floating-point numbers that MATLAB typically uses. However, it is necessary for MATLAB to interpret 8-bit image data differently from 64-bit data. This table summarizes these differences:double
, the value 1 points to the first row in the colormap, the value 2 points to the second row, and so on. In a uint8
indexed image, there is an offset; the value 0 points to the first row in the colormap, the value 1 points to the second row, and so on. The uint8
convention is also used in graphics file formats, and enables 8-bit indexed images to support up to 256 colors. Note that when you read in an indexed image with imread
, the resulting image array is always of class uint8
. (The colormap, however, is of class double
; see below.)
If you want to convert a uint8
indexed image to double
, you need to add 1 to the result. For example:
X64 = double(X8) + 1;To convert from
double
to uint8
, you need to first subtract 1, and then use round
to ensure all the values are integers:
X8 = uint8(round(X64 - 1));The order of the operations must be as shown in these examples, because you cannot perform mathematical operations on
uint8
arrays.
When you write an indexed image using imwrite
, MATLAB automatically converts the values if necessary.
Colormaps in MATLAB are alway m
-by-3 arrays of double-precision floating-point numbers in the range [0, 1]. In most graphics file formats, colormaps are stored as integers, but MATLAB does not support colormaps with integer values. imread
and imwrite
automatically convert colormap values when reading and writing files.
In a truecolor image of class double
, the data values are floating-point numbers in the range [0, 1]. In a truecolor image of class uint8
, the data values are integers in the range [0, 255].
If you want to convert a truecolor image from one data type to the other, you must rescale the data. For example, this call converts a uint8
truecolor image to double
:
RGB64 = double(RGB8)/255;This statement converts a
double
truecolor image to uint8
:
RGB8 = uint8(round(RGB*255));The order of the operations must be as shown in these examples, because you cannot perform mathematical operations on
uint8
arrays.
When you write a truecolor image using imwrite
, MATLAB automatically converts the values if necessary.
You can set default Image properties on the Axes, Figure, and Root levels:
set(0,'DefaultImageProperty',PropertyValue...) set(gcf,'DefaultImageProperty',PropertyValue...) set(gca,'DefaultImageProperty',PropertyValue...)Where
Property
is the name of the Image property and PropertyValue
is the value you are specifying. Use set
and get
to access Image properties.
The following table lists all Image properties and provides a brief description of each. The property name links take you to an expanded description of the properties.Property Name |
Property Description |
Property Value |
Data Defining the Object | ||
CData |
The image data |
Values: matrix or m-by-n-by-3 array Default: enter image;axis image ij and see |
CDataMapping |
Specify the mapping of data to colormap |
Values: scaled , direct Default: direct |
XData |
Control placement of image along x-axis |
Values: [min max] Default: [1 size(CData,2)] |
YData |
Control placement of image along y-axis |
Values: [min max] Default: [1 size(CData,1)] |
Controlling the Appearance | ||
Clipping |
Clipping to Axes rectangle |
Values: on , off Default: on |
EraseMode |
Method of drawing and erasing the image (useful for animation) |
Values: normal , none , xor , background Default: normal |
SelectionHighlight |
Highlight image when selected (Selected property set to on ) |
Values: on , off Default: on |
Visible |
Make the image visible or invisible |
Values: on , off Default: on |
Controlling Access to Objects | ||
HandleVisibility |
Determines if and when the the Line's handle is visible to other functions |
Values: on , callback , off Default: on |
HitTest |
Determine if image can become the current object (see the Figure CurrentObject property) |
Values: on , off Default: on |
General Information About the Image | ||
Children |
Image objects have no children |
Values: [] (empty matrix) |
Parent |
The parent of an image object is always an Axes object |
Value: Axes handle |
Selected |
Indicate whether image is in a "selected" state. |
Values: on , off Default: on |
Tag |
User-specified label |
Value: any string Default: '' (empty string) |
Type |
The type of graphics object (read only) |
Value: the string 'image' |
|
User-specified data |
Values: any matrix Default: [] (empty matrix) |
Properties Related to Callback Routine Execution | ||
|
Specify how to handle callback routine interruption |
Values: cancel , queue Default: queue |
|
Define a callback routine that executes when a mouse button is pressed on over the image |
Values: string Default: empty string |
|
Define a callback routine that executes when an image is created |
Values: string Default: empty string |
|
Define a callback routine that executes when the image is deleted (via close or delete ) |
Values: string Default: empty string |
|
Determine if callback routine can be interrupted |
Values: on , off Default: on (can be interrupted) |
|
Associate a context menu with the image |
Values: handle of a Uicontrextmenu |