Convert RGB image to indexed image

`[X,cmap] = rgb2ind(RGB,Q)`

`[X,cmap] = rgb2ind(RGB,tol)`

`X = rgb2ind(RGB,inmap)`

`___ = rgb2ind(___,dithering)`

Uniform Quantization — If you specify

`tol`

, then`rgb2ind`

uses uniform quantization to convert the image. Uniform quantization cuts the RGB color cube into smaller cubes of length`tol`

. For example, if you specify a`tol`

of 0.1, then the edges of the cubes are one-tenth the length of the RGB cube. The total number of small cubes is:t = (floor(1/tol)+1)^3

Each cube represents a single color in the output image. Therefore,

`t`

is the maximum length of the colormap .`rgb2ind`

removes any colors that don’t appear in the input image, so the actual colormap can be smaller than`t`

.Minimum Variance Quantization — If you specify

`Q`

, then`rgb2ind`

uses minimum variance quantization. Minimum variance quantization cuts the RGB color cube into smaller boxes (not necessarily cubes) of different sizes, depending on how the colors are distributed in the image. If the input image actually uses fewer colors than the number specified, then the output colormap is also smaller.Inverse Colormap — If you specify an input colormap

`inmap`

, then`rgb2ind`

uses colormap mapping. The inverse colormap algorithm quantizes the specified colormap into 32 distinct levels per color component. Then, for each pixel in the input image, the closest color in the quantized colormap is found.

[1] Spencer W. Thomas, "Efficient Inverse Color Map Computation",
*Graphics Gems II*, (ed. James Arvo), Academic Press: Boston.
1991. (includes source code)

`cmunique`

| `dither`

| `imapprox`

| `ind2rgb`

- Image Types
- Reduce the Number of Colors in an Image (Image Processing Toolbox)