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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Image data from axes


A = getimage(h)
[x, y, A] = getimage(h)
[..., A, flag] = getimage(h)
[...] = getimage


A = getimage(h) returns the first image data contained in the graphics object h. h can be a figure, axes, or image. A is identical to the image CData; it contains the same values and is of the same class (uint8, uint16, double, or logical) as the image CData. If h is not an image or does not contain an image, A is empty.

[x, y, A] = getimage(h) returns the image XData in x and the YData in y. XData and YData are two-element vectors that indicate the range of the x-axis and y-axis.

[..., A, flag] = getimage(h) returns an integer flag that indicates the type of image h contains. This table summarizes the possible values for flag.


Type of Image


Not an image; A is returned as an empty matrix


Indexed image


Intensity image with values in standard range ([0,1] for single and double arrays, [0,255] for uint8 arrays, [0,65535] for uint16 arrays)


Intensity data, but not in standard range


RGB image


Binary image

[...] = getimage returns information for the current axes object. It is equivalent to [...] = getimage(gca).

Class Support

The output array A is of the same class as the image CData. All other inputs and outputs are of class double.


For int16 and single images, the image data returned by getimage is of class double, not int16 or single. This is because the getimage function gets the data from the image object's CData property and image objects store int16 and single image data as class double.

For example, create an image object of class int16. If you retrieve the CData from the object and check its class, it returns double.

h = imshow(ones(10,'int16')); 

Therefore, if you get the image data using the getimage function, the data it returns is also of class double. The flag return value is set to 3.

[img,flag] = getimage(h);

The same is true for an image of class single. Getting the CData directly from the image object or by using getimage, the class of the returned data is double.

h = imshow(ones(10,'single'));
[img,flag] = getimage(h);

For images of class single, the flag return value is set to 2 because single and double share the same dynamic range.


collapse all

Display image directly from a file using imshow and create a variable in the workspace that contains the image data.

imshow rice.png

I = getimage;

Display image directly from a file using the Image Viewer app (imtool) and create a variable in the workspace that contains the image data.

h = imtool('cameraman.tif');

I = getimage(imgca);

See Also


Introduced before R2006a

Was this topic helpful?