chromadapt
Adjust color balance of RGB image with chromatic adaptation
Description
adjusts the color balance of sRGB image B
= chromadapt(A
,illuminant
)A
according to the
scene illuminant. The illuminant must be in the same color space as the input
image.
adjusts the color balance of B
= chromadapt(A
,illuminant
,Name,Value
)A
using name-value arguments to
control additional options.
Examples
Color Balance Image by Specifying Gray Pixel
Read and display an image with a strong yellow color cast.
A = imread('hallway.jpg'); imshow(A) title('Original Image')
Pick a pixel in the image that should look white or gray, such as a point on a pillar. Do not pick a saturated pixel, such as a point on the ceiling light. Display the selected point in green.
x = 2800; y = 1000; gray_val = impixel(A,x,y); drawpoint('Position',[x y],'Color','g');
Use the selected color as reference for the scene illumination, and correct the white balance of the image.
B = chromadapt(A,gray_val);
Display the corrected image. The pillars now appear white as expected, and the rest of the image has no yellow tint.
imshow(B)
title('White-Balanced Image')
Color Balance Image in Linear RGB Color Space
Open an image file containing minimally processed linear RGB intensities.
A = imread("foosballraw.tiff");
The image data is the raw sensor data after correcting the black level and scaling to 16 bits per pixel. Interpolate the intensities to reconstruct color. The color filter array pattern is RGGB.
A = demosaic(A,"rggb");
Display the image. Because the image is in linear RGB color space, apply gamma correction so the image appears correctly on the screen.
A_sRGB = lin2rgb(A);
imshow(A_sRGB)
title("Original Image")
The image has a ColorChecker® chart in the scene. To get the color of the ambient light, display the RGB values of a pixel in one of the neutral patches of the chart. The intensity of the red channel is lower than the intensity of the other two channels, which indicates that the light is bluish green.
x = 1510; y = 1250; light_color = [A(y,x,1) A(y,x,2) A(y,x,3)]
light_color = 1x3 uint16 row vector
7361 14968 10258
Balance the color channels of the image. Use the ColorSpace
name-value argument to specify that the image and the illuminant are expressed in linear RGB.
B = chromadapt(A,light_color,"ColorSpace","linear-rgb");
Display the color-balanced image with gamma correction.
B_sRGB = lin2rgb(B);
imshow(B_sRGB)
title("Color-Balanced Image")
Confirm that the gray patch has been color balanced. The three color channels in the color-balanced gray patch have similar intensities, as expected.
patch_color = [B(y,x,1) B(y,x,2) B(y,x,3)]
patch_color = 1x3 uint16 row vector
13010 13010 13010
Input Arguments
A
— RGB image
m-by-n-by-3 numeric array
RGB image, specified as an m-by-n-by-3 numeric array.
Data Types: single
| double
| uint8
| uint16
illuminant
— Scene illuminant
3-element numeric vector
Scene illuminant, specified as a 3-element numeric vector. The illuminant
must be in the same color space as the input image,
A
.
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.
Example: I2 = chromadapt(I,uint8([22 97
118]),ColorSpace="linear-rgb")
adjusts the color balance of an image,
I
, in linear RGB color space.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: I2 = chromadapt(I,uint8([22 97
118]),"ColorSpace","linear-rgb")
adjusts the color balance of an
image, I
, in linear RGB color space.
ColorSpace
— Color space
"srgb"
(default) | "adobe-rgb-1998"
| "prophoto-rgb"
| "linear-rgb"
Color space of the input image and illuminant, specified as
"srgb"
, "adobe-rgb-1998"
,
"prophoto-rgb"
, or
"linear-rgb"
. Use the
"linear-rgb"
option to adjust the color balance
of an RGB image whose intensities are linear.
Data Types: char
| string
Method
— Chromatic adaptation method
"bradford"
(default) | "vonkries"
| "simple"
Chromatic adaptation method used to scale the RGB values in
A
, specified as one of these values.
"bradford"
—Scale using the Bradford cone response model"vonkries"
—Scale using the von Kries cone response model"simple"
—Scale using the illuminant
Data Types: char
| string
Output Arguments
B
— Color-balanced RGB image
m-by-n-by-3 numeric array
Color-balanced RGB image, returned as an
m-by-n-by-3 numeric array of the
same data type as A
.
References
[1] Lindbloom, Bruce. Chromatic Adaptation. http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html.
Version History
Introduced in R2017bR2022b: Support for ProPhoto (ROMM RGB) color space
chromadapt
now supports the ProPhoto (ROMM RGB) color space,
which has a wider gamut than the sRGB and Adobe RGB 1998 color spaces. To use the
ProPhoto color space, specify the ColorSpace
name-value
argument as "prophoto-rgb"
.
See Also
whitepoint
| colorangle
| illumgray
| illumpca
| illumwhite
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)