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.


Image data from axes


I = getimage(h)
[x,y,I] = getimage(h)
[___,flag] = getimage(h)
[___] = getimage


I = getimage(h) returns the first image data contained in the graphics object h.

[x,y,I] = getimage(h) also returns the image extent in the x and y direction.

[___,flag] = getimage(h) also returns a flag that indicates the type of image that h contains.


[___] = getimage returns information for the current axes object.


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);

Input Arguments

collapse all

Handle to a figure, axes, uipanel, or image graphics object, specified as a handle. If h is an axes or figure handle containing multiple images, then getimage uses the first image returned by findobj(h,'Type','image').

Output Arguments

collapse all

Image data, returned as a numeric array. I 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, then I is empty.

Image extent in the x direction, returned as a 2-element numeric vector of the form [xmin xmax]. x is identical to the image XData.

Data Types: double

Image extent in the y direction, returned as a 2-element numeric vector of the form [ymin ymax]. y is identical to the image YData.

Data Types: double

Image type, returned as an integer with one of these values:


Type of Image


Not an image; I 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

Data Types: double


  • For images of data type int16 and single, 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.

See Also


Introduced before R2006a

Was this topic helpful?