Convert RGB image to indexed image
[X,map] = rgb2ind(RGB,n)
X = rgb2ind(RGB, map)
[X,map] = rgb2ind(RGB, tol)
[___] = rgb2ind(___,dither_option)
[X,map] = rgb2ind(RGB,n)
converts
the RGB image to an indexed image X
using minimum
variance quantization and dithering. map
contains
at most n
colors. n
must be
less than or equal to 65,536.
X = rgb2ind(RGB, map)
converts
the RGB image to an indexed image X
with colormap map
using
the inverse colormap algorithm and dithering. size(map,1)
must
be less than or equal to 65,536.
[X,map] = rgb2ind(RGB, tol)
converts
the RGB image to an indexed image X
using uniform
quantization and dithering. map
contains at most (floor(1/tol)+1)^3
colors. tol
must
be between 0.0 and 1.0.
[___] = rgb2ind(___,dither_option)
enables
or disables dithering. dither_option
can be one
of these values.
'dither' (default) | Dithers, if necessary, to achieve better color resolution at the expense of spatial resolution |
'nodither' | Maps each color in the original image to the closest color in the new map. No dithering is performed. |
Note
The values in the resultant image |
The input image can be of class uint8
, uint16
, single
,
or double
. If the length of map
is
less than or equal to 256, the output image is of class uint8
.
Otherwise, the output image is of class uint16
.
The value 0
in the output array X
corresponds
to the first color in the colormap.
Read and display a truecolor uint8
JPEG image
of a nebula.
RGB = imread('ngc6543a.jpg'); figure('Name','RGB Image') imagesc(RGB) axis image zoom(4)
Convert RGB to an indexed image with 32 colors
[IND,map] = rgb2ind(RGB,32); figure('Name','Indexed image with 32 Colors') imagesc(IND) colormap(map) axis image zoom(4)
[1] Spencer W. Thomas, "Efficient Inverse Color Map Computation", Graphics Gems II, (ed. James Arvo), Academic Press: Boston. 1991. (includes source code)