This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Gamma Correction

imadjust maps low to bottom, and high to top. By default, the values between low and high are mapped linearly to values between bottom and top. For example, the value halfway between low and high corresponds to the value halfway between bottom and top.

imadjust can accept an additional argument that specifies the gamma correction factor. Depending on the value of gamma, the mapping between values in the input and output images might be nonlinear. For example, the value halfway between low and high might map to a value either greater than or less than the value halfway between bottom and top.

Gamma can be any value between 0 and infinity. If gamma is 1 (the default), the mapping is linear. If gamma is less than 1, the mapping is weighted toward higher (brighter) output values. If gamma is greater than 1, the mapping is weighted toward lower (darker) output values.

The figure illustrates this relationship. The three transformation curves show how values are mapped when gamma is less than, equal to, and greater than 1. (In each graph, the x-axis represents the intensity values in the input image, and the y-axis represents the intensity values in the output image.)

Plots Showing Three Different Gamma Correction Settings

Specify Gamma when Adjusting Contrast

This example shows how to specify gamma when adjusting contrast with the imadjust function. By default, imadjust uses a gamma value of 1, which means that it uses a linear mapping between intensity values in the original image and the output image. A gamma value less than 1 weights the mapping toward higher (brighter) output values. A gamma value of more than 1 weights output values toward lower (darker) output values.

Read an image into the workspace. This example reads an indexed image and then converts it into a grayscale image.

[X,map] = imread('forest.tif');
I = ind2gray(X,map);

Adjust the contrast, specifying a gamma value of less than 1 (0.5). Notice that in the call to imadjust, the example specifies the data ranges of the input and output images as empty matrices. When you specify an empty matrix, imadjust uses the default range of [0,1]. In the example, both ranges are left empty. This means that gamma correction is applied without any other adjustment of the data.

J = imadjust(I,[],[],0.5);

Display the original image with the contrast-adjusted image.