The Image Viewer app is an image display and exploration tool that presents an integrated environment for displaying images and performing common image processing tasks. Image Viewer provides access to several other tools:
Pixel Information tool — for getting information about the pixel under the pointer
Pixel Region tool — for getting information about a group of pixels
Distance tool — for measuring the distance between two pixels
Image Information tool — for getting information about image and image file metadata
Adjust Contrast tool and associated Window/Level tool — for adjusting the contrast of the image displayed in Image Viewer and modifying the actual image data. You can save the adjusted data to the workspace or a file.
Crop Image tool — for defining a crop region on the image and cropping the image. You can save the cropped image to the workspace or a file.
Display Range tool — for determining the display range of the image data
In addition, Image Viewer provides several navigation aids that can help explore large images:
Overview tool — for determining what part of the image is currently visible in the Image Viewer and changing this view.
Pan tool — for moving the image to view other parts of the image
Zoom tool — for getting a closer view of any part of the image.
Scroll bars — for navigating over the image.
The figure shows an image displayed in Image Viewer with many of the related tools open and active.
To start the Image Viewer app, click Image Viewer on the
Apps tab, or use the
imtool function. You can also start another Image Viewer from
within an existing Image Viewer by using the New
option from the File menu.
To bring image data into Image Viewer, you can use either the Open or Import from Workspace options from the File menu — see Import Image Data from Workspace into Image Viewer App.
You can also specify the name of the MATLAB® workspace variable that contains image data when you call
imtool, as follows:
moon = imread('moon.tif'); imtool(moon)
Alternatively, you can specify the name of the graphics file containing the image. This syntax can be useful for scanning through graphics files.
When you specify a file name, the image data is not stored in a
MATLAB workspace variable. To bring the image displayed in Image Viewer
into the workspace, use the
getimage function or the Export to Workspace option from the File menu — see Export Image Data from Image Viewer App to Workspace.
Image Viewer attempts to display an image in its entirety at 100%
magnification (one screen pixel for each image pixel) and always honors any magnification
value you specify. If the image is too large to fit in a figure on the screen, then
Image Viewer shows only a portion of the image, adding scroll bars to allow
navigation to parts of the image that are not currently visible. If the specified
magnification would make the image too large to fit on the screen, then Image
Viewer scales the image to fit, without issuing a warning. This behavior is the
default behavior, specified by the
'InitialMagnification' parameter value
To override this default initial magnification behavior for a particular call to
imtool, specify the
For example, to view an image at 150% magnification, use this code.
pout = imread('pout.tif'); imtool(pout, 'InitialMagnification', 150)
You can also specify the
'fit' as the initial magnification value. In
imtool scales the image to fit the default size of a figure
Another way to change the default initial magnification behavior of Image
Viewer is to set the
preference. The magnification value you specify remains in effect until you change it. To
set the preference, use
iptsetpref or open the Image Processing
Toolbox™ Preferences panel. To open the preferences panel, call
iptprefs or select File > Preferences in the Image Viewer menu. To learn more about toolbox preferences,
When Image Viewer 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 an interpolation method, see Resize an Image with imresize Function.
A color map is a matrix that can have any number of rows, but must have three columns. Each row in the colormap is interpreted as a color, with the first element specifying the intensity of red, the second green, and the third blue.
To specify the color map used to display an indexed image or a grayscale image in Image Viewer, select the Choose Colormap option on the Tools menu. This activates the Choose Colormap tool. Using this tool you can select one of the MATLAB color maps or select a color map variable from the workspace.
When you select a color map, Image Viewer executes the color map function you specify and updates the image displayed. You can edit the color map command in the Evaluate Colormap text box; for example, you can change the number of entries in the color map (default is 256). You can enter your own color map function in this field. Press Enter to execute the command.
When you choose a color map, the image updates to use the new map. If you click OK, Image Viewer applies the color map and closes the Choose Colormap tool. If you click Cancel, the image reverts to the previous color map.
If you want to show the correspondence between data values and the displayed colors, then you can add a color bar. A color bar is especially useful if the displayed data has an unconventional range. To add a color bar, select the Print to Figure option from the File menu. Image Viewer displays the image in a separate figure window to which you can add a color bar. For example, see Add Color Bar to Displayed Grayscale Image.
To import image data from the MATLAB workspace into Image Viewer, use the Import from Workspace option on the File menu. In the dialog box, select the workspace variable that you want to import into the workspace.
The following figure shows the Import from Workspace dialog box. You can use the Filter menu to limit the images included in the list to certain image types, i.e., binary, indexed, intensity (grayscale), or truecolor.
To export the image displayed in Image Viewer to the MATLAB workspace, use the Export to Workspace option
on the Image Viewer File menu or the
getimage function. (When exporting data, changes to the display range
are not preserved.) In the dialog box, shown below, you specify the name you want to assign
to the variable in the workspace. By default, Image Viewer pre-fills the variable
name field with
BW, for binary images,
truecolor images, and
I for grayscale or indexed images.
If Image Viewer contains an indexed image, this dialog box also contains a field where you can specify the name of the associated color map.
You can also use the
getimage function to bring image data from
Image Viewer into the MATLAB workspace.
getimage function retrieves the image data
CData) from the current image object. Use the toolbox function
imgca to get the image object displayed in Image Viewer. The
following example assigns the image data from
moon.tif to the variable
moon if the figure window in which it is displayed is currently
moon = getimage(imgca);
To save the image data displayed in Image Viewer, select the
Save as option from the File
menu. Image Viewer opens the Save Image dialog box, shown in the following
figure. Use this dialog box to navigate your file system to determine where to save the
image file and specify the name of the file. Choose the graphics file format you want to use
from among the image file formats listed in the Files of Type
menu. If you do not specify a file name extension, then Image Viewer adds an
extension to the file associated with the file format selected, such as
.jpg for the JPEG format.
Changes you make to the display range are not saved. If you would like to preserve
your changes, use
To close Image Viewer, use the Close button
in the window title bar or select the Close option from the
File menu. If you used the
function to start Image Viewer, then you can get the figure object that contains
the app. You can use this object to close the app. When you close Image Viewer,
any related tools that are currently open also close.
Because Image Viewer does not make its component graphics objects visible,
Image Viewer does not close when you call the MATLAB
close all command. If you want to close multiple Image
Viewers, use the syntax
or select Close all from the Image Viewer File menu.
To print the image displayed in the Image Viewer, select the Print to Figure option from the File menu. Image Viewer opens another figure window and displays the image. Use the Print option on the File menu of this figure window to print the image. See Print Images for more information.