Main Content

contrast

Create grayscale colormap for indexed image

Description

newmap = contrast(I) creates a grayscale colormap that enhances the contrast of the indexed image I. The new colormap increases the contrast among pixels that are difficult to distinguish visually, but have slightly different brightness values.

example

newmap = contrast(I,m) returns the new colormap as an m-by-3 array. Use this syntax when you want the new colormap to have a different number of rows than the original colormap.

example

Examples

collapse all

Load clown to get image X and its associated colormap, map. Display the image produced by X and map.

load clown 
imagesc(X)
colormap(map)

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

Use contrast to return a gray colormap that enhances the contrast of image X. Then update the display with the new colormap.

newmap = contrast(X);
colormap(newmap)

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

Load clown to get image X. Then create a contrast-enhancing colormap, and display the image using that colormap.

load clown
imagesc(X)
newmap1 = contrast(X);
colormap(newmap1)

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

Next, use contrast to create another colormap containing only 10 shades of gray. Update the display with the new colormap. Notice that the shadow areas are lighter and have lost some detail.

newmap2 = contrast(X,10);
colormap(newmap2)

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

Input Arguments

collapse all

Indexed image to enhance, specified as an m-by-n numeric matrix. An indexed image is an m-by-n numeric matrix whose elements are indices into a colormap. Each row of the colormap specifies the red, green, and blue components of a color.

Data Types: single | double

Number of rows in the new colormap, specified as a numeric scalar value.

Note

When m is significantly different than the number of rows in the original colormap, the new colormap might be missing some values or contain repeated values. This discrepancy might reduce the amount of tonal detail in the enhanced image.

Example: newmap = contrast(I,50) returns a colormap containing 50 rows.

Version History

Introduced before R2006a

See Also

| |