| Image Processing Toolbox™ | ![]() |
| On this page… |
|---|
Specifying the Initial Image Magnification Importing Image Data from the Workspace Exporting Image Data to the Workspace |
The Image Tool is an image display and exploration tool that presents an integrated environment for displaying images and performing common image processing tasks. The Image Tool 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 the Image Tool 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, the Image Tool 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 Tool 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 following figure shows the image displayed in the Image Tool with many of the related tools open and active.
Image Tool and Related Tools

To start the Image Tool, use the imtool function. You can also start another Image Tool from within an existing Image Tool by using the New option from the File menu.
The imtool function supports many syntax options. For example, when called without any arguments, it opens an empty Image Tool.
imtool
To bring image data into this empty Image Tool, you can use either the Open or Import from Workspace options from the File menu — see Importing Image Data from the Workspace.
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.
imtool('moon.tif');Note When you use this syntax, the image data is not stored in a MATLAB workspace variable. To bring the image displayed in the Image Tool into the workspace, you must use the getimage function or the Export from Workspace option from the Image Tool File menu — see Exporting Image Data to the Workspace. |
The imtool function 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 big to fit in a figure on the screen, the Image Tool 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, imtool scales the image to fit, without issuing a warning. This is the default behavior, specified by the imtool 'InitialMagnification' parameter value 'adaptive'.
To override this default initial magnification behavior for a particular call to imtool, specify the InitialMagnification parameter. 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 text string 'fit' as the initial magnification value. In this case, imtool scales the image to fit the default size of a figure window.
You can also change the default initial magnification behavior of imtool by setting the ImtoolInitialMagnification toolbox preference. The magnification value you specify affects every call to imtool for the current MATLAB session. To make this preference persist between sessions, include the command to set the preference in your startup.m file. To learn more about toolbox preferences, see Setting the Values of Toolbox Preferences.
When imtool 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, see .
A colormap 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 the Image Tool, select the Choose Colormap option on the Tools menu. This activates the Choose Colormap tool, shown below. Using this tool you can select one of the MATLAB colormaps or select a colormap variable from the MATLAB workspace.
When you select a colormap, the Image Tool executes the colormap function you specify and updates the image displayed. You can edit the colormap command in the Evaluate Colormap text box; for example, you can change the number of entries in the colormap (default is 256). You can enter your own colormap function in this field. Press Enter to execute the command.
When you choose a colormap, the image updates to use the new map. If you click OK, the Image Tool applies the colormap and closes the Choose Colormap tool. If you click Cancel, the image reverts to the previous colormap.
Image Tool Choose Colormap Tool

To import image data from the MATLAB workspace into the Image Tool, use the Import from Workspace option on the Image Tool File menu. In the dialog box, shown below, you 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.
Image Tool Import from Workspace Dialog Box

To export the image displayed in the Image Tool to the MATLAB workspace, you can use the Export to Workspace option on the Image Tool File menu. In the dialog box, shown below, you specify the name you want to assign to the variable in the workspace. By default, the Image Tool prefills the variable name field with BW, for binary images, RGB, for truecolor images, and I for grayscale or indexed images.
If the Image Tool contains an indexed image, this dialog box also contain a field where you can specify the name of the associated colormap.
Image Tool Export Image to Workspace Dialog Box

You can also use the getimage function to bring image data from the Image Tool into the MATLAB workspace.
The getimage function retrieves the image data (CData) from the current Handle Graphics® image object. Because, by default, the Image Tool does not make handles to objects visible, you must use the toolbox function imgca to get a handle to the image axes displayed in the Image Tool. 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 active.
moon = getimage(imgca);
To save the image data displayed in the Image Tool, select the Save as option from the Image Tool File menu. The Image Tool 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 many common image file formats listed in the Files of Type menu. If you do not specify a file name extension, the Image Tool adds an extension to the file associated with the file format selected, such as .jpg for the JPEG format.
Image Tool Save Image Dialog Box

To close the Image Tool window, use the Close button in the window title bar or select the Close option from the Image Tool File menu. You can also use the imtool function to return a handle to the Image Tool and use the handle to close the Image Tool. When you close the Image Tool, any related tools that are currently open also close.
Because the Image Tool does not make the handles to its figure objects visible, the Image Tool does not close when you call the MATLAB close all command. If you want to close multiple Image Tools, use the syntax
imtool close all
or select Close all from the Image Tool File menu.
To print the image displayed in the Image Tool, select the Print to Figure option from the File menu. The Image Tool 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 Printing Images for more information.
![]() | Displaying Images Using the imshow Function | Exploring Images Using Image Tool Navigation Aids | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |