gray2ind
Convert grayscale or binary image to indexed image
Description
Examples
Convert Grayscale Image to Indexed Image
Read grayscale image into the workspace.
I = imread('cameraman.tif');
Convert the image to an indexed image using gray2ind
. This example creates an indexed image with 16 indices.
[X, map] = gray2ind(I, 16);
Display the indexed image.
imshow(X, map);
Input Arguments
I
— Grayscale image
numeric array
Grayscale image, specified as a numeric array of any dimension.
The
gray2ind
function expects images of data type
double
and single
to have values in the range [0, 1].
If I
has values outside the range [0, 1], then you can rescale values to
the expected range by using the rescale
function.
Data Types: single
| double
| int16
| uint8
| uint16
BW
— Binary image
logical array
Binary image, specified as a logical array of any dimension.
Data Types: logical
c
— Number of colormap colors
positive integer
Number of colormap colors, specified as a positive integer between 1 and 65536.
If the input image is grayscale, then the default value of
c
is64
.If the input image is binary, then the default value of
c
is2
.
Output Arguments
X
— Indexed image
numeric array
Indexed image, returned as a numeric array of the same dimensionality as
the input grayscale or binary image. If the colormap length is less than or
equal to 256, then the class of the output image is uint8
; otherwise it is uint16
.
Data Types: uint8
| uint16
cmap
— Colormap
c-by-3 numeric matrix
Extended Capabilities
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Image Processing on a GPU.
Version History
Introduced before R2006aR2022b: Support for GPU acceleration
gray2ind
now supports GPU acceleration
(requires Parallel Computing Toolbox™).
R2021b: Support for thread-based environments
gray2ind
now supports thread-based
environments.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)