Main Content

imapprox

Approximate indexed image by reducing number of colors

Description

example

[Y,newmap] = imapprox(X,map,Q)approximates the colors in indexed imageXand associated colormapmapby using minimum variance quantization withQquantized colors.imapproxreturns the indexed imageYwith colormapnewmap.

[Y,newmap] = imapprox(X,map,tol)approximates the colors in indexed imageXand associated colormapmapby using uniform quantization with tolerancetol.

Y= imapprox(X,map,inmap)approximates the colors in indexed imageXand associated colormapmapby using inverse colormap mapping with colormapinmap. The inverse colormap algorithm finds the colors ininmapthat best match the colors inmap.

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

Examples

collapse all

Load an indexed image of a mandrill's face. Display imageXusing its associated colormap,map, which has 220 colors.

figure loadmandrillimage(X) colormap(map) axisoffaxisimage

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

Reduce the number of colors in the indexed image from 220 to only 16 colors by producing a new image,Y, and its associated colormap,newmap.

图[Y, newmap] = imapprox (X,地图,16);图像(Y) colormap(newmap) axisoffaxisimage

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

Input Arguments

collapse all

Indexed image with many colors, specified as anm-by-nmatrix of nonnegative integers.

Data Types:single|double|uint8|uint16

Colormap with many colors associated with indexed imageX, specified as ad3矩阵with values in the range [0, 1]. Each row ofmapis a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.

Data Types:double

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 colormapnewmaphasQor fewer colors.

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

Colormap with fewer colors used for inverse colormap mapping, 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

Perform dithering, specified as'dither'or'nodither'. Dithering increases the color resolution at the expense of spatial resolution. For more information, seedither.

If you select'nodither', thenimapproxdoes not perform dithering. Instead, the function maps each color in the original image to the closest color in the new colormap.

Output Arguments

collapse all

Indexed image with fewer colors, returned as anm-by-nmatrix of positive integers. If the length ofnewmap(orimmap, if specified) is less than or equal to 256, then the output image is of classuint8. Otherwise, the output image is of classdouble.

Data Types:double|uint8

Colormap with fewer colors associated with the output indexed imageY,返回c3矩阵with values in the range [0, 1]. Each row ofnewmapis 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

Algorithms

imapproxusesrgb2indto create a new colormap that uses fewer colors. For more information about quantization and inverse colormap mapping, see theAlgorithmsofrgb2ind.

Version History

Introduced before R2006a

See Also

||

Topics