Main Content

contrast

Create grayscale colormap to enhance image contrast

Description

example

newmap = contrast(I) creates a grayscale colormap that enhances the contrast of 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.

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

Image to enhance, specified as an m-by-n matrix or an m-by-n-by-3 truecolor image.

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

| |