Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imshow

Syntax

imshow(I)
imshow(X,map)
imshow(filename)
imshow(I,[low high])
imshow(___,Name,Value)
himage = imshow(___)
imshow(I,RI)
imshow(X,RX,map)
imshow(gpuarrayIM,___)

Description

example

imshow(I) displays image I in a 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. imshow optimizes figure, axes, and image object properties for image display.

example

imshow(X,map) displays the indexed image X with the colormap map. A colormap matrix can 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 to 1.0.

example

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

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

imshow(___,Name,Value) displays an image, using name-value pairs to control aspects of the operation.

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

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

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

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

Examples

collapse all

Display a grayscale image by reading an RGB image into the workspace and converting it to a grayscale image.

Read RGB image into the workspace.

RGB = imread('peppers.png');

Convert the image to grayscale.

I = rgb2gray(RGB);

Display the grayscale image.

imshow(I)

Display an image stored in a file.

imshow('peppers.png');

Read a sample indexed image, corn.tif, into the workspace, and then display it.

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

Read a sample indexed image, corn.tif, into the workspace, and then display it.

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

Change the colormap for the image using the colormap function and specifying the target axes as the first input argument. Use the original colormap without the red component.

newmap = map;
newmap(:,1) = 0;
colormap(gca,newmap)

Read image into the workspace.

I = imread('pout.tif');

Display the image. Note the axes limits reflect the size of the image.

figure; imshow(I)

Create a spatial referencing object associated with the image. Use the referencing object to set the x- and y-axes limits in the world coordinate system.

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

Display the image, specifying the spatial referencing object. Note the change to the x- and y-axes limits.

figure; imshow(I,RI);

Read image into a gpuArray.

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

Display it.

figure; imshow(X)

Input Arguments

collapse all

Input image, specified as a scalar, vector, or matrix representing a grayscale, RGB, or binary image. Multi-plane image inputs must be RGB images of size m-by-n-by-3. An RGB image can be uint8, uint16, single, or double. A grayscale image can be any numeric data type. A binary image is of class logical.

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

Indexed image, specified as a 2-D array of real numeric values. The values in X are indices into the colormap specified by map.

Data Types: single | double | uint8 | logical

Colormap, specified as an m-by-3 array of type single or double in the range [0 1], or an m-by-3 array of type uint8. Each row specifies an RGB color value.

Data Types: single | double | uint8

File name, specified as a character vector. The image must be readable by imread. The imshow function 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.

Example: imshow('peppers.png')

Data Types: char

Grayscale image display range, specified as a two-element vector. For more information, see the 'DisplayRange' name-value pair argument.

Example: [50 250]

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

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.

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: imshow('board.tif','Border','tight')

collapse all

Figure window border space, specified as the comma-separated pair consisting of 'Border' and either 'tight' or 'loose'. When set to 'loose', the figure window includes space around the image in the figure. When set to 'tight', the figure window does not include any space around the image in the figure.

If the image is very small or if the figure contains other objects besides an image and its axes, imshow might use a border regardless of how this parameter is set.

Example: imshow('board.tif','Border','tight')

Data Types: char

Colormap, specified as the comma-separated pair consisting of 'Colormap' and an m-by-3 matrix. imshow uses this to set the colormap for the axes. Use this parameter to view grayscale images in false color. If you specify an empty colormap ([]), then imshow ignores this parameter.

Note

Starting in R2016b, imshow changes the colormap for the axes that contains the image instead of the figure.

Example: newmap = copper; imshow('board.tif','Colormap',newmap)

Data Types: double

Display range of a grayscale image, specified as a two-element vector of the form [low high]. The imshow function displays the value low (and any value less than low) as black, and it displays the value high (and any value greater than high) as white. Values between low and high 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(:))]. In other words, use the minimum value in I as black, and the maximum value as white.

Note

Including the parameter name is optional, except when the image is specified by a file name. The syntax imshow(I,[low high]) is equivalent to imshow(I,'DisplayRange',[low high]). If you call imshow with a file name, then you must specify the 'DisplayRange' parameter.

Example: h = imshow(I,'DisplayRange',[0 80]);

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

Initial magnification of image display, specified as the comma-separated pair consisting of 'InitialMagnification' and a numeric scalar or 'fit'. If set to 100, then imshow displays the image at 100% magnification (one screen pixel for each image pixel). If set to 'fit', then imshow scales the entire image to fit in the window.

Initially, imshow always displays the entire image. If the magnification value is so large that the image is too big 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', then 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 you use imshow with the 'Reduce' parameter, the initial magnification must be 'fit'.

Example: h = imshow(I,'InitialMagnification','fit');

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

Parent axes of image object, specified as the comma-separated pair consisting of 'Parent' and an axes object. Use the 'Parent' name-value argument to build a UI that gives you control of the figure and axes properties.

Indicator for subsampling image, specified as the comma-separated pair consisting of 'Reduce' and either 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

X-axis limits of nondefault coordinate system, specified as the comma-separated pair consisting of 'XData' and a two-element vector. This argument establishes a nondefault spatial coordinate system by specifying the image XData. The value can have more than two elements, but imshow uses only the first and last elements.

Example: 'XData',[100 200]

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

Y-axis limits of nondefault coordinate system, specified as the comma-separated pair consisting of 'YData' and a two-element vector. The value can have more than two elements, but imshow uses only the first and last elements.

Example: 'YData',[100 200]

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

Output Arguments

collapse all

Image created by imshow, specified as an image object.

Tips

  • To change the colormap after you create the image, use the colormap command. Specify the axes that contains the image as the first input argument and the colormap you want as the second input argument. For an example, see Change Colormap of Displayed Image.

  • You can display multiple images with different colormaps in the same figure using imshow with the subplot function.

  • If you have Image Processing Toolbox™, you can use the Image Viewer app as an integrated environment for displaying images and performing common image processing tasks.

  • If you have Image Processing Toolbox, you can use the iptsetpref function to set toolbox preferences that modify the behavior of imshow.

  • The imshow function is not supported when you start MATLAB with the -nojvm option.

Introduced before R2006a

Was this topic helpful?