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 Handle 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.
Type of Image
Not an image; A is returned as an empty matrix
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
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')); class(get(h,'CData'))
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); class(img)
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')); class(get(h,'CData')) [img,flag] = getimage(h); class(img)
For images of class single, the flag return value is set to 2 because single and double share the same dynamic range.
After using imshow or imtool to display an image directly from a file, use getimage to get the image data into the workspace.
imshow rice.png I = getimage; imtool cameraman.tif I = getimage(imgca);