Main Content

Image Viewer

View and explore images

Description

The Image Viewer app enables you to interactively explore images and perform common image processing tasks. Using the app, you can:

  • Load an image from a file or from the workspace.

  • Zoom and navigate the image using an overview display.

  • View image metadata, pixel values, and the display range.

  • Measure the distances between pixels or the area within a drawn polygon region.

  • View grayscale images using a built-in or custom colormap.

  • Crop the image, or adjust the contrast of the image.

  • Export measurements to the workspace, and export the modified image to the workspace or as an image file.

To learn more, see Get Started with Image Viewer App.

Image Viewer app

Open the Image Viewer App

  • MATLAB® Toolstrip: On the Apps tab, under Image Processing and Computer Vision, click the Image Viewer app icon.

  • MATLAB command prompt: Use the imageViewer function.

Examples

expand all

Display a color image from a file.

imageViewer("board.tif")

Image Viewer app showing RGB image

Display a grayscale image.

I = imread("cameraman.tif");
imageViewer(I)

Image Viewer app showing grayscale image with the default display range

Display the same grayscale image, adjusting the display range.

imageViewer(I,DisplayRange=[0 80]);

Image Viewer app showing grayscale image with a modified display range

Display an indexed image.

[X,map] = imread("trees.tif");
imageViewer(X,Colormap=map)

Image Viewer app showing indexed image with a colormap

Related Examples

Programmatic Use

expand all

imageViewer opens Image Viewer in an empty state.

  • To load an image from a file, select Import Image > From File.

  • To load an image stored as a variable in the workspace, select Import Image > From Workspace.

imageViewer(I) opens Image Viewer and displays the grayscale, RGB, or binary image I. Specify I as one of these values.

  • An m-by-n numeric matrix representing a grayscale image. Image Viewer displays the image using the default display range for the data type.

    • If I is an integer data type, the default display range is equal to the data type range. For example, the default display range for uint8 is [0, 255], such that 0 appears black and 255 appears white.

    • If I is of data type single or double, the default display range is [0, 1], such that 0 appears black and 1 appears white.

    Image Viewer expects images of data type single or double to have values in the range [0, 1]. If the app detects values outside of this range, the app displays a warning and disables the contrast adjustment tools. To enable contrast adjustment, rescale the image to the range [0, 1] by using the rescale function.

  • An m-by-n-by-3 numeric array representing an RGB image.

  • An m-by-n logical matrix representing a binary image.

imageViewer(filename) opens Image Viewer and displays the image file with the filename filename. Specify filename as a character vector or string scalar.

imageViewer(___,Colormap=cmap) displays the specified grayscale or binary image in Image Viewer using the colormap cmap. Setting the colormap of an RGB image has no effect. Specify cmap as a c-by-3 numeric matrix with values in the range [0, 1], where c is the number of colors in the colormap. You can also create a colormap matrix using a predefined colormap function, such as parula or jet.

For example, imageViewer(I,Colormap=parula) displays the grayscale image I using the parula colormap.

imageViewer(___,DisplayRange=dispRange) displays a grayscale or indexed image in Image Viewer and applies an initial contrast adjustment to the image data. Specify dispRange as one of these values.

  • 2-element vector of the form [low high]Image Viewer displays pixels with values less than or equal to low as black and pixels with values greater than or equal to high as white. Image Viewer displays pixel values within the display range as intermediate shades of gray using the default number of gray levels. If the image is of data type single or double, then the values low and high must be in the range [0, 1].

    For example, if the grayscale image I is of data type uint8, then imageViewer(I,DisplayRange=[15 140]) rescales the data such that pixels with values less than or equal to 15 appear black and pixels with values greater than or equal to 140 appear white.

  • []Image Viewer calculates the values for low and high as min(I(:)) and max(I(:)), respectively. The minimum value in I displays as black, and the maximum value displays as white.

    For example, for a grayscale image I of data type uint8, with a minimum pixel value of 8 and a maximum pixel value of 245, the syntax imageViewer(I,DisplayRange=[]) scales the display range such that pixels with a value of 8 appear black and pixels with a value of 245 appear white.

    Image Viewer expects images of data type single or double to have values in the range [0, 1]. If the minimum or maximum value of the image is outside this range, and you specify the DisplayRange argument as [], the function returns an error. To display the image and enable contrast adjustment, first rescale the image values by using the rescale function.

You can undo contrast changes caused by the DisplayRange argument in the app. On the Contrast tab of the app toolstrip, click Undo Changes.

imageViewer(___,InitialMagnification=initMag) displays the image with initial magnification initMag. Specify initMag as one of these values.

  • "fit"Image Viewer resizes the entire image to fit in the window.

  • A positive number — Image Viewer resizes the entire image as a percentage of the original image size. For example, if you specify 100, then Image Viewer displays the image at 100% magnification (one screen pixel for each image pixel).

    For example, imageViewer(I,InitialMagnification=50) displays image I at 50% of the original image dimensions.

imageViewer(___,Interpolation=interp) specifies the interpolation technique interp used to resize the image for display. Specify interp as "nearest" for nearest neighbor interpolation or "bilinear" for bilinear interpolation. The default interpolation technique is "nearest". You can also change the interpolation method within the app.

For example, imageViewer(I,Interpolation="bilinear") resizes image I using bilinear interpolation.

imageViewer close closes all open instances of Image Viewer.

Tips

  • Image Viewer does not close when you use the close all command. If you want to close multiple instances of the Image Viewer app, use the syntax imageViewer close.

  • If you load an image with a data range occupying less than 1/4 of the display range for the data type, the app prompts you to adjust the contrast before displaying the image. Select Yes to set the display range limits to match the data range and increase the image contrast. Select No to display the raw image with low contrast. By default, the app remembers your selection and applies it for all low-contrast images. Clear the checkbox to be prompted each time you load a low contrast image.

  • Display multilevel images and images that are too large to fit into memory by using the blockedImage object and bigimageshow function. The blockedImage object manages large and multilevel images to balance memory requirements with display performance. If an image file requires too much memory to display, you can use the makeMultiLevel2D function to add a coarse resolution level, which you can display using bigimageshow.

Version History

Introduced before R2006a

expand all