主要内容

RGB2IND

Convert RGB image to indexed image

Description

example

[X,cmap] = rgb2ind(RGB,Q)converts the RGB image to an indexed imageXwith associated colormapcmap使用最小方差量化与Q量化的颜色和抖动。

[X,cmap] = rgb2ind(RGB,tol)converts the RGB image to an indexed image using uniform quantization with tolerancetol和抖动。

X= rgb2ind(RGB,iNMAP)converts the RGB image to an indexed image using the inverse colormap algorithm with specified colormapiNMAP和抖动。

___= rgb2ind(___,dithering)enables or disables dithering.

Examples

collapse all

Read and display a truecoloruint8JPEG image of a nebula.

rgb = imread('ngc6543a.jpg');图Imagesc(RGB)轴imagezoom(4)

Figure contains an axes object. The axes object contains an object of type image.

Convert RGB to an indexed image with 32 colors.

[IND,MAP] = RGB2IND(RGB,32);图Imagesc(IND)colormap(MAP)轴imagezoom(4)

Figure contains an axes object. The axes object contains an object of type image.

Input Arguments

collapse all

RGB图像, specified as anm-经过-n-by-3阵列.

Data Types:single|double|uint8|uint16

Number of quantized colors used for minimum variance quantization, specified as a positive integer that is less than or equal to 65,536. The returned colormapcmaphasQ或者fewer colors.

Tolerance used for uniform quantization, specified as a number in the range [0, 1]. The returned colormapcmaphas(floor(1/tol)+1)^3或者fewer colors.

输入菌落, specified as ac3矩阵with values in the range [0, 1]. Each row ofiNMAPis a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap. The colormap has a maximum of 65,536 colors.

Data Types:double

执行抖动,指定为'dither'或者'''. Dithering increases the color resolution at the expense of spatial resolution. For more information, seedither.

If you select''', thenRGB2IND不执行抖动。取而代之的是,该功能将原始图像中的每种颜色映射到新Colormap中的最接近的颜色。

Output Arguments

collapse all

Indexed image, returned as anm-经过-n非负整数的矩阵。如果长度mapis less than or equal to 256, then the output image is of classuint8. Otherwise, the output image is of classuint16. The value0in the output arrayXcorresponds to the first color in the colormap.

Note

The values in imageX是索引到colormapmapand should not be used in mathematical processing, such as filtering operations.

Data Types:uint8|uint16

colormap,回到c3矩阵with values in the range [0, 1]. Each row ofcmapis a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap. The colormap has a maximum of 65,536 colors.

Data Types:double

算法

  • Uniform Quantization — If you specifytol, thenRGB2IND使用统一量化来转换图像。均匀量化将RGB颜色立方体切成长度的较小立方体tol. For example, if you specify atolof 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,tis the maximum length of the colormap .RGB2INDremoves any colors that don’t appear in the input image, so the actual colormap can be smaller thant.

  • 最小差异量化 - 如果指定Q, thenRGB2IND使用最小方差量化。最小方差量化将RGB颜色立方体切成不同尺寸的较小盒子(不一定是立方体),这取决于图像中的颜色分布方式。如果输入图像实际上使用的颜色少于指定的数字,则输出colormap也小。

  • Inverse Colormap — If you specify an input colormapiNMAP, thenRGB2INDuses 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,“有效的逆色图计算”,图形Gems II, (ed. James Arvo), Academic Press: Boston. 1991. (includes source code)

Version History

在R2006a之前引入