To display image data, use the imshow function. The following example reads an image into the workspace and
then displays the image in a figure window using the imshow
function.
moon = imread('moon.tif');
imshow(moon);
You can also pass imshow the name of a file containing an
image.
imshow('moon.tif');This syntax can be useful for scanning through images. Note, however, that when you use
this syntax, imread does not store the image data in the workspace. If
you want to bring the image into the workspace, you must use the getimage
function, which retrieves the image data from the current image object. This example assigns
the image data from moon.tif to the variable moon, if
the figure window in which it is displayed is currently active.
moon = getimage;
For more information about using imshow to display the various image
types supported by the toolbox, see Display Different Image Types.
By default, imshow attempts to display an image in its
entirety at 100% magnification (one screen pixel for each image pixel). However, if an image
is too large to fit in a figure window on the screen at 100% magnification,
imshow scales the image to fit onto the screen and issues a warning
message.
To override the default initial magnification behavior for a particular call to
imshow, specify the InitialMagnification parameter.
For example, to view an image at 150% magnification, use this code.
pout = imread('pout.tif'); imshow(pout, 'InitialMagnification', 150)
imshow attempts to honor the magnification you specify. However, if
the image does not fit on the screen at the specified magnification,
imshow scales the image to fit. You can also specify the
'fit' as the initial magnification value. In this case,
imshow scales the image to fit the current size of the figure
window.
To change the default initial magnification behavior of imshow, set
the ImshowInitialMagnification toolbox preference. To set the preference,
open the Image Processing Toolbox™ Preferences dialog box by calling iptprefs or, on the MATLAB®
Home tab, in the Environment section, click
Preferences.
When imshow scales an image, it uses interpolation to determine the
values for screen pixels that do not directly correspond to elements in the image matrix.
For more information about specifying interpolation methods, see Resize an Image with imresize Function.
By default, when imshow displays an image in a figure, it surrounds
the image with a gray border. You can change this default and suppress the border using the
'border' parameter, as shown in the following example.
imshow('moon.tif','Border','tight')The following figure shows the same image displayed with and without a border.

The 'border' parameters affect only the image being displayed in the
call to imshow. If you want all the images that you display using
imshow to appear without the gray border, set the Image Processing Toolbox
'ImshowBorder' preference to 'tight'. You can also use
preferences to include visible axes in the figure. For more information about preferences,
see iptprefs.