Skip to Main Content Skip to Search
Product Documentation

imagesc - Scale data and display image object

Example of imagesc function output

Alternatives

To plot a selected matrix as an image use the Plot Selector in the Workspace Browser, or use the Figure Palette Plot Catalog. Manipulate image characteristics in plot edit mode with the Property Editor. For details, see Plotting Tools — Interactive Plotting in the MATLAB Graphics documentation and Creating Graphics from the Workspace Browser in the MATLAB Desktop Tools documentation.

Syntax

imagesc(C)
imagesc(x,y,C)
imagesc(...,clims)
imagesc('PropertyName',PropertyValue,...)
h = imagesc(...)

Description

The imagesc function scales image data to the full range of the current colormap and displays the image. (See Examples for an illustration.)

imagesc(C) displays C as an image. Each element of C corresponds to a rectangular area in the image. The values of the elements of C are indices into the current colormap that determine the color of each patch.

imagesc(x,y,C) displays C as an image and specifies the bounds of the x- and y-axis with vectors x and y. If x(1) > x(2) or y(1) > y(2), the image is flipped left-right or up-down, respectively. If x and y are scalars, the image is translated to the specified location (x,y) such that the upper left corner of the image starts at (x,y).

imagesc(...,clims) normalizes the values in C to the range specified by clims and displays C as an image. clims is a two-element vector that limits the range of data values in C. These values map to the full range of values in the current colormap.

imagesc('PropertyName',PropertyValue,...) is the low-level syntax of the imagesc function. It specifies only property name/property value pairs as input arguments. See for a list of the property names and their values.

h = imagesc(...) returns the handle for an image graphics object.

Tips

x and y do not affect the elements in C; they only affect the annotation of the axes. If length(x) > 2 or length(y) > 2, imagesc ignores all except the first and last elements of the respective vector.

imagesc creates an image with CDataMapping set to scaled, and sets the axes CLim property to the value passed in clims.

You cannot interactively pan or zoom outside the x-limits or y-limits of an image.

By default, imagesc plots the y-axis from lowest to highest value, top to bottom. To reverse this, type set(gca,'YDir','normal'). This will reverse both the y-axis and the image.

Examples

You can expand midrange color resolution by mapping low values to the first color and high values to the last color in the colormap by specifying color value limits (clims). If the size of the current colormap is 81-by-3, the statements

clims = [ 10 60 ]
imagesc(C,clims)

map the data values in C to the colormap as shown in this illustration and the code that follows:

In this example, the left image maps to the gray colormap using the statements

load clown
figure
subplot(1,2,1)
imagesc(X)
colormap(gray)
axis image
title('Default CLim (= [1 81])')

The right image has values between 10 and 60 scaled to the full range of the gray colormap using the statements

subplot(1,2,2)
clims = [10 60];
imagesc(X,clims)
colormap(gray)
axis image
title('CLim = [10 60]')

This example shows how to shift the image starting from origin to a position (100, 100),

i = imread('eight.tif');
figure; subplot(2,2,1); imagesc(i);
axis([0 400 0 400]);
colormap(gray);
subplot(2,2,2); imagesc(100,100,i); 
axis([0 400 0 400]);
colormap(gray);

The figure output is as:

The top right corner of the image is now starting from (100,100) instead of the origin.

Passing vector values with the image scales the image to the specified size of 400–by–400.

figure; imagesc(1:400,1:400,i); 
colormap(gray);

See Also

colorbar | colormap | image | imfinfo | imread | imwrite | pcolor | surf | surface

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS