rgb2lin
Linearize gamma-corrected RGB values
Description
Examples
Linearize an sRGB Image
Open an image. The JPEG file format saves images in the gamma-corrected sRGB color space.
A = imread('foosball.jpg');
Display the image.
imshow(A)
title('Scene With sRGB Gamma Correction')
Undo the gamma correction and linearize the image by using the rgb2lin
function. Optionally, specify the data type of the linearized values.
B = rgb2lin(A,'OutputType','double');
Display the linearized image. Shadows in the linearized image are darker than in the original image, as expected.
imshow(B)
title('Scene Without sRGB Gamma Correction')
Input Arguments
A
— Gamma-corrected RGB color values
numeric array
Gamma-corrected RGB color values, specified as a numeric array in one of the following formats.
c-by-3 colormap. Each row specifies one RGB color value.
m-by-n-by-3 image
m-by-n-by-3-by-p stack of images
Data Types: single
| double
| uint8
| uint16
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: B = lin2rgb(I,'ColorSpace','adobe-rgb-1998')
linearizes
the gamma-corrected image, I
, according to the Adobe RGB (1998)
standard.
ColorSpace
— Color space of the input image
'srgb'
(default) | 'adobe-rgb-1998'
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
OutputType
— Data type of output RGB values
'double'
| 'single'
| 'uint8'
| 'uint16'
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
B
— Linearized RGB color values
numeric array
Linearized RGB color values, returned as a numeric array of the same size
as the input A
.
Algorithms
Linearization Using the sRGB Standard
sRGB tristimulus values are linearized using the following parametric curve:
f(u) = -f(-u), u < 0
f(u) = c ⋅ u, 0 ≤ u < d
f(u) = (a ⋅ u + b)ɣ, u ≥ d,
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ɣ,
with
ɣ = 2.19921875
References
[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 4.3.5.2, May 2005, p.12.
Version History
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)