Main Content

imadjust

Adjust image intensity values or colormap

Description

example

J= imadjust(I)maps the intensity values in grayscale imageIto new values inJ. By default,imadjustsaturates the bottom 1% and the top 1% of all pixel values. This operation increases the contrast of the output imageJ.

This syntax is equivalent toimadjust(I,stretchlim(I)).

J= imadjust(I,[low_in high_in])maps intensity values inIto new values inJsuch that values betweenlow_inandhigh_inmap to values between 0 and 1.

example

J= imadjust(I,[low_in high_in],[low_out high_out])maps intensity values inIto new values inJsuch that values betweenlow_inandhigh_inmap to values betweenlow_outandhigh_out.

J= imadjust(I,[low_in high_in],[low_out high_out],gamma)maps intensity values inIto new values inJ, wheregammaspecifies the shape of the curve describing the relationship between the values inIandJ.

example

J= imadjust(RGB,[low_in high_in],___)maps the values in truecolor imageRGBto new values inJ. You can apply the same mapping or unique mappings for each color channel.

newmap= imadjust(cmap,[low_in high_in],___)maps the values in colormapcmapto new values innewmap. You can apply the same mapping or unique mappings for each color channel.

Examples

collapse all

Read a low-contrast grayscale image into the workspace and display it.

I = imread('pout.tif'); imshow(I)

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

Adjust the contrast of the image so that 1% of the data is saturated at low and high intensities, and display it.

J = imadjust(I); figure imshow(J)

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

Read a low-contrast grayscale image into the workspace and display it.

I = imread('pout.tif'); imshow(I);

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

Adjust the contrast of the image, specifying contrast limits.

K = imadjust(I,[0.3 0.7],[]); figure imshow(K)

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

Read an RGB image into the workspace and display it.

RGB = imread('football.jpg'); imshow(RGB)

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

Adjust the contrast of the RGB image, specifying contrast limits.

RGB2 = imadjust(RGB,[.2 .3 0; .6 .7 1],[]); figure imshow(RGB2)

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

Read an image into the workspace, and display it.

I = imread('pout.tif'); imshow(I)

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

Calculate the standard deviation and the image mean for stretching.

n = 2; Idouble = im2double(I); avg = mean2(Idouble); sigma = std2(Idouble);

Adjust the contrast based on the standard deviation.

J = imadjust(I,[avg-n*sigma avg+n*sigma],[]);

Display the adjusted image.

imshow(J)

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

Input Arguments

collapse all

Grayscale image, specified as anm-by-nnumeric matrix.

Data Types:single|double|int16|uint8|uint16

Truecolor image, specified as anm-by-n-by-3 numeric array.

Data Types:single|double|int16|uint8|uint16

Colormap, specified as ac-by-3 numeric matrix with values in the range [0, 1]. Each row is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.

Data Types:double

Contrast limits for the input image, specified in one of the following forms:

Input Type Value Description
Grayscale image 1-by-2 vector of the form[low_in high_in] Specifies the contrast limits in the input grayscale image that you want to map to values in the output image. Values must be in the range[0 1.0]. The valuelow_inmust be less than the valuehigh_in.
RGB image or colormap 2-by-3 matrix of the form[low_RGB_triplet; high_RGB_triplet] Specifies the contrast limits in the input RGB image or colormap that you want to map to values in the output image or colormap. Each row in the array is an RGB color triplet. Values must be in the range[0 1]. The valuelow_RGB_tripletmust be less than the valuehigh_RGB_triplet.
RGB image or colormap 1-by-2 vector of the form[low_in high_in] Specifies the contrast limits in the input RGB image that you want to map to values in the output image. Each value must be in the range[0 1.0]. The valuelow_inmust be less than the valuehigh_in. If you specify a 1-by-2 vector with an RGB image or colormap, thenimadjustapplies the same adjustment to each color plane or channel.
All types [] If you specify an empty matrix ([]), thenimadjustuses the default limits[0 1].

imadjustclips value belowlow_inand abovehigh_in: Values belowlow_inmap tolow_outand values abovehigh_inmap tohigh_out.

Data Types:single|double

Contrast limits for the output image, specified in one of the following forms:

Input Type Value Description
Grayscale image 1-by-2 vector of the form[low_out high_out] Specifies the contrast limits of the output grayscale image. Each value must be in the range[0 1].
RGB image or colormap 2-by-3 matrix of the form[low_RGB_triplet; high_RGB_triplet] Specifies the contrast limits of the output RGB image or colormap. Each row in the array is an RGB color triplet. Values must be in the range[0 1].
RGB image or colormap 1-by-2 vector of the form[low_out high_out] Specifies the contrast limits in the output image. Each value must be in the range[0 1]. If you specify a 1-by-2 vector with an RGB image or colormap, thenimadjustapplies the same adjustment to each plane or channel.
All types [] If you specify an empty matrix ([]), thenimadjustuses the default limits[0 1].

Ifhigh_outis less thanlow_out, thenimadjustreverses the output image, as in a photographic negative.

Data Types:single|double

Shape of curve describing the relationship of input and output values, specified as a nonnegative scalar or a 1-by-3 numeric vector.

  • Ifgammais less than 1, thenimadjustweights the mapping toward higher (brighter) output values.

  • Ifgamma大于1,那么imadjustweights the mapping toward lower (darker) output values.

  • Ifgammais a 1-by-3 vector, thenimadjustapplies a unique gamma to each color component or channel.

  • If you omit the argument, thengammadefaults to1(linear mapping).

Data Types:double

Output Arguments

collapse all

Adjusted image, returned as a grayscale or RGB image.Jhas the same size and class as the input grayscale imageIor truecolor imageRGB.

Data Types:single|double|int16|uint8|uint16

Adjusted colormap, returned as anc-by-3 numeric matrix of the same class as the input colormap,map.

Data Types:single|double

Extended Capabilities

Introduced before R2006a