| Contents | Index |
[X, map] = gray2ind(I,n)
[X, map] = gray2ind(BW,n)
[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.
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.
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);grayslice | ind2gray | mat2gray

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |