Documentation Center

  • Trial Software
  • Product Updates

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);

See Also

| |

Was this topic helpful?