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. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


Linearize gamma-corrected RGB values


B = rgb2lin(A)
B = rgb2lin(A,Name,Value)


B = rgb2lin(A) undoes the gamma correction of the sRGB values in image A so that B contains linear RGB values.


B = rgb2lin(A,Name,Value) undoes gamma correction using name-value pairs to control additional options.


collapse all

Open an image. The JPEG file format saves images in the gamma-corrected sRGB color space.

A = imread('foosball.jpg');

Display the image. To shrink the image so that it appears fully on the screen, set the optional initial magnification to a value less than 100.

title('Scene With sRGB Gamma Correction')

To undo the gamma correction and linearize the image, use the rgb2lin function. Optionally, specify the data type of the linearized values.

B = rgb2lin(A,'OutputType','double');

Display the linearized image, setting the optional magnification.

title('Scene Without sRGB Gamma Correction')

Shadows in the linearized image are darker than in the original image, as expected.

Input Arguments

collapse all

Gamma-corrected RGB image, specified as a real, nonsparse, m-by-n-by-3 array.

Data Types: single | double | uint8 | uint16

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: B = lin2rgb(I,'ColorSpace','adobe-rgb-1998') linearizes the gamma-corrected image, I, according to the Adobe RGB (1998) standard.

collapse all

Color space of the input image, specified as the comma-separated pair consisting of 'ColorSpace' and 'srgb' or 'adobe-rgb-1998'.

Data Types: char | string

Data type of the output RGB values, specified as the comma-separated pair consisting of 'OutputType' and 'double', 'single', 'uint8', or 'uint16'. By default, the output data type is the same as the data type of A.

Data Types: char | string

Output Arguments

collapse all

Linearized RGB image, returned as a real, nonsparse m-by-n-by-3 array.


collapse all

Linearization Using the sRGB Standard

sRGB tristimulus values are linearized using the following parametric curve:

    f(u) = -f(-u),                u < 0

    f(u) = cu,                0 ≤ u < d

    f(u) = (au + b)ɣ,      ud,

where u represents a color value with these parameters:

    a = 1/1.055

    b = 0.055/1.055

    c = 1/12.92

    d = 0.04045

    ɣ = 2.4

Linearization Using the Adobe RGB (1998) Standard

Adobe RGB (1998) tristimulus values are linearized using a simple power function:

    v = uɣ,


    ɣ = 2.19921875


[1] Ebner, Marc. "Gamma Correction." Color Constancy. Chichester, West Sussex: John Wiley & Sons, 2007.

[2] Adobe Systems Incorporated. "Inverting the color component transfer function." Adobe RGB (1998) Color Image Encoding. Section, May 2005, p.12.

See Also

Introduced in R2017b

Was this topic helpful?