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.

Add Colorbar to Displayed Image

To display an image with a colorbar that indicates the range of intensity values, first use the imshow function to display the image in a MATLAB® figure window and then call the colorbar function to add the colorbar to the image.

When you add a colorbar to an axes object that contains an image object, the colorbar indicates the data values that the different colors in the image correspond to.

If you want to add a colorbar to an image displayed in the Image Viewer, select the Print to Figure option from the File menu. The Image Viewer displays the image in a separate figure window to which you can add a colorbar.

Seeing the correspondence between data values and the colors displayed by using a colorbar is especially useful if you are displaying unconventional range data as an image, as described under Display Grayscale Images with Unconventional Ranges.

In the example below, a grayscale image of class uint8 is filtered, resulting in data that is no longer in the range [0,255].

RGB = imread('saturn.png');
I = rgb2gray(RGB);
h = [1 2 1; 0 0 0; -1 -2 -1];
I2 = filter2(h,I);
imshow(I2,'DisplayRange',[]), colorbar

Was this topic helpful?