Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

imshow

Syntax

  • himage = imshow(___)

Description

example

imshow(I) displays the image I in a graphics figure, where I is a grayscale, RGB (truecolor), or binary image. For binary images, imshow displays pixels with the value 0 (zero) as black and 1 as white.

example

imshow(I,RI) displays the image I with associated 2-D spatial referencing object RI.

example

imshow(I,[low high]) displays the grayscale image I, specifying the display range as a two-element vector, [low high]. For more information, see the DisplayRange parameter.

example

imshow(X,map) displays the indexed image X with the colormap map. A colormap matrix may have any number of rows, but it must have exactly 3 columns. Each row is interpreted as a color, with the first element specifying the intensity of red light, the second green, and the third blue. Color intensity can be specified on the interval [0.0 1.0].

imshow(X,RX,map) displays the indexed image X with associated 2-D spatial referencing object RX and colormap MAP.

example

imshow(filename) displays the image stored in the graphics file specified by the character vector filename.

imshow(___,Name,Value,...) displays the image, specifying additional options with one or more Name,Value pair arguments, using any of the previous syntaxes.

example

imshow(gpuarrayIM,___) displays the image contained in a gpuArray. This syntax requires the Parallel Computing Toolbox™.

himage = imshow(___) returns the image object created by imshow.

Examples

collapse all

Specify image file.

imshow('board.tif')

Read indexed image and associated colormap from file and display it.

[X,map] = imread('trees.tif');
imshow(X,map)

Read grayscale image from file and display it.

I = imread('cameraman.tif');
imshow(I)

Read grayscale image and specify display range.

I = imread('cameraman.tif');
h = imshow(I,[0 80]);

Read image into workspace.

I = imread('pout.tif');

Create a spatial referencing object associated with the image. Then specify X and Y limits in a world coordinate system.

RI = imref2d(size(I));
RI.XWorldLimits = [0 3];
RI.YWorldLimits = [2 5];

Display the image, specifying the spatial referencing object.

imshow(I,RI);

Read image into a gpuArray.

X = gpuArray(imread('pout.tif'));

Display it.

figure; imshow(X)

Related Examples

Input Arguments

collapse all

Input image, specified as a grayscale, RGB, or binary image.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Indexed image, specified as a 2-D array of real numeric values. The values in X are an index into Map, an n-by-3 array of RGB values.

Data Types: single | double | uint8 | logical

Colormap, specified as an n-by-3 array. Each row specified an RGB color value.

Data Types: single | double | uint8 | logical

Name of file containing an image, specified as a character vector. The image must be readable by imread or by dicomread. imshow displays the image but does not store the image data in the MATLAB® workspace. If the file contains multiple images, imshow displays the first image in the file.

Data Types: char

2-D spatial referencing object associated with input image, specified as an imref2d object.

2-D spatial referencing object associated with an indexed image, specified as a imref2d object.

Image to be processed on a graphics processing unit (GPU), specified as a gpuArray.

Display range of the image, specified as a two-element vector.

Example: [50 250]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Border','tight'

collapse all

Control whether figure window includes a border, specified as 'tight' or 'loose'. There can still be a border if the image is very small, or if there are other objects besides the image and its axes in the figure.

Data Types: char

Value of figure colormap property, specified as a 2-D, real, m-by-3 matrix. Use this parameter to view grayscale images in false color. If you specify an empty colormap ([]), imshow ignores this parameter.

Data Types: double

Display range of a grayscale image, specified as a two-element vector [LOW HIGH]. imshow displays the value low (and any value less than low) as black, and the value high (and any value greater than high) as white. Values in between are displayed as intermediate shades of gray, using the default number of gray levels. If you specify an empty matrix ([]), imshow uses [min(I(:)) max(I(:))]; that is, the minimum value in I is black, and the maximum value is white.

    Note:   The syntax imshow(I,[LOW HIGH]) is equivalent to imshow(I,'DisplayRange',[LOW HIGH]). However, when calling imshow with a filename, you must specify the 'DisplayRange' parameter.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Initial magnification used to display an image, specified as a numeric scalar or the character vector'fit'.

When set to 100, imshow displays the image at 100% magnification (one screen pixel for each image pixel). When set to 'fit', imshow scales the entire image to fit in the window.

On initial display, imshow always displays the entire image. If the magnification value is large enough that the image would be too large to display on the screen, imshow warns and displays the image at the largest magnification that fits on the screen.

If the image is displayed in a figure with its 'WindowStyle' property set to 'docked', imshow warns and displays the image at the largest magnification that fits in the figure.

Note: If you specify the axes position (using subplot or axes), imshow ignores any initial magnification you might have specified and defaults to the 'fit' behavior.

When used with the 'Reduce' parameter, only 'fit' is allowed as an initial magnification.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char

Parent axes of image object, specified as an axes object. This is the axes created by imshow.

    Note:   If you are building a GUI where you want to control the figure and axes properties, be sure to use the imshow(..., 'Parent', ax) syntax.

Indicator for subsampling image, specified as true, false, 1, or 0. This argument is valid only when you use it with the name of a TIFF file. Use the Reduce argument to display overviews of very large images.

Data Types: logical

Limits along X axis of a nondefault spatial coordinate system, specified as a two-element vector. Establishes a nondefault spatial coordinate system by specifying the image XData. The value can have more than two elements, but only the first and last elements are actually used.

Example: [100 200]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Limits along Y axis of a nondefault spatial coordinate system, specified as a two-element vector. The value can have more than two elements, but only the first and last elements are actually used.

Example: [100 200]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Image object created by imshow, specified as an image object.

Alternative Functionality

App

imshow is the fundamental image display function, optimizing figure, axes, and image object property settings for image display. The other toolbox display function, imtool provides all the image display capabilities of imshow but also provides access to several other tools for navigating and exploring images, such as the Pixel Region tool, Image Information tool, and the Adjust Contrast tool. imtool presents an integrated environment for displaying images and performing some common image processing tasks.

The imshow function is not supported when MATLAB is started with the -nojvm option.

You can access imshow through the Plot Selector workspace tool, which is represented by this icon: . In your workspace, select the data you want to display. The Plot Selector icon changes to look like this: . Scroll down to Image Processing Toolbox Plots. Select imshow(I).

More About

collapse all

Tips

  • You can use the iptsetpref function to set several toolbox preferences that modify the behavior of imshow.

    • 'ImshowBorder' controls whether imshow displays the image with a border around it.

    • 'ImshowAxesVisible' controls whether imshow displays the image with the axes box and tick labels.

    • 'ImshowInitialMagnification' controls the initial magnification for image display, unless you override it in a particular call by specifying imshow(...,'InitialMagnification',initial_mag).

    For more information about these preferences, see iptprefs.

Introduced before R2006a

Was this topic helpful?