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.

gray2ind

Convert grayscale or binary image to indexed image

Syntax

[X, map] = gray2ind(I,n)
[X, map] = gray2ind(BW,n)

Description

[X, map] = gray2ind(I,n) converts the grayscale image I to an indexed image X. n specifies the size of the colormap, gray(n). n must be an integer between 1 and 65536. If n is omitted, it defaults to 64.

[X, map] = gray2ind(BW,n) converts the binary image BW to an indexed image X. n specifies the size of the colormap, gray(n). If n is omitted, it defaults to 2.

gray2ind scales and then rounds the intensity image to produce an equivalent indexed image.

Class Support

The input image I can be logical, uint8, uint16, int16, single, or double and must be a real and nonsparse. The image I can have any dimension. The class of the output image X is uint8 if the colormap length is less than or equal to 256; otherwise it is uint16.

Examples

Convert a grayscale image into an indexed image and then view the result.

I = imread('cameraman.tif');
[X, map] = gray2ind(I, 16);
imshow(X, map);

Introduced before R2006a

Was this topic helpful?