Main Content


Create grayscale colormap to enhance image contrast



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.


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.


collapse all

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

load clown 

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);

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

load clown
newmap1 = contrast(X);

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);

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.


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

| |