Accelerating the pace of engineering and science

Documentation Center

• Trial Software
• Product Updates

imapprox

Approximate indexed image by reducing number of colors

Syntax

[Y,newmap] = imapprox(X,map,n)
[Y,newmap] = imapprox(X,map,tol)
Y = imapprox(X,map,newmap)
Y = imapprox(...,dither_option)

Description

[Y,newmap] = imapprox(X,map,n) approximates the colors in the indexed image X and associated colormap map by using minimum variance quantization. imapprox returns the indexed image Y with colormap newmap, which has at most n colors.

[Y,newmap] = imapprox(X,map,tol) approximates the colors in X and map through uniform quantization. newmap contains at most (floor(1/tol)+1)^3 colors. tol must be between 0 and 1.0.

Y = imapprox(X,map,newmap) approximates the colors in map by using colormap mapping to find the colors in newmap that best match the colors in map.

Y = imapprox(...,dither_option) enables or disables dithering. dither_option is a string that can have one of these values.

Value

Description

{'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.

Class Support

The input image X can be of class uint8, uint16, or double. The output image Y is of class uint8 if the length of newmap is less than or equal to 256. If the length of newmap is greater than 256, Y is of class double.

Examples

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

```load mandrill
figure('color','k')
image(X)
colormap(map)
size(map)         % See that the color map has 220 entries

ans =
220     3

axis off          % Remove axis ticks and numbers
axis image        % Set aspect ratio to obtain square pixels    ```

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:

```figure('color','k')
[Y, newmap] = imapprox(X, map, 16);
size(newmap)   % See that the new color map has 16 entries

ans =
16     3

image(Y)
colormap(newmap)
axis off       % Remove axis ticks and numbers
axis image     % Set aspect ratio to obtain square pixels
```

More About

expand all

Algorithms

imapprox uses rgb2ind to create a new colormap that uses fewer colors.

See Also

Was this topic helpful?