This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Adjust color balance of RGB image with chromatic adaptation


B = chromadapt(A,illuminant)
B = chromadapt(A,illuminant,Name,Value)



B = chromadapt(A,illuminant) adjusts the color balance of sRGB image A according to the scene illuminant. The illuminant must be in the same color space as the input image.


B = chromadapt(A,illuminant,Name,Value) adjusts the color balance of A using name-value pairs to control additional options.


collapse all

Read an image with a strong yellow color cast. Display the image, specifying an optional magnification to shrink the size of the displayed image.

A = imread('hallway.jpg');
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.

x = 2800;
y = 1000;
gray_val = [A(y,x,1) A(y,x,2) A(y,x,3)];

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, setting an optional initial magnification.

title('White-Balanced Image')

The pillars are now white as expected, and the rest of the image has no yellow tint.

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. To shrink the image so that it appears fully on the screen, set the optional initial magnification to a value less than 100

A_sRGB = lin2rgb(A);
title('Original Image')

The image has a ColorChecker chart in the scene. To get the color of the ambient light, pick a pixel on one of the neutral patches of the chart.

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

The intensity of the red channel is lower than the intensity of the other two channels, which indicates the light is bluish green.

Balance the color channels of the image. Use the 'ColorSpace' option to specify that the image and the illuminant are expressed in linear RGB.

B = chromadapt(A,light_color,'ColorSpace','linear-rgb');

Display the corrected image, applying gamma correction and setting the initial magnification.

B_sRGB = lin2rgb(B);
title('White-Balanced Image')

Confirm that the gray patch has been color balanced.

patch_color = [B(y,x,1) B(y,x,2) B(y,x,3)]
patch_color = 1x3 uint16 row vector

   13010   13010   13010

The three color channels in the color-balanced gray patch have similar intensities, as expected.

Input Arguments

collapse all

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

Data Types: single | double | uint8 | uint16

Scene illuminant, specified as a real, nonempty, 3-element vector. The illuminant must be in the same color space as the input image, A.

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: I2 = chromadapt(I,uint8([22 97 118]),'ColorSpace','linear-rgb') adjusts the color balance of an image, I, in linear RGB color space.

collapse all

Color space of the input image and illuminant, specified as the comma-separated pair consisting of 'ColorSpace' and 'srgb', 'adobe-rgb-1998', 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

collapse all

Chromatic adaptation method used to scale the RGB values in A, specified as the comma-separated pair consisting of 'Method' and one of:

  • '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

collapse all

Color-balanced RGB image, returned as an m-by-n-by-3 array. B has the same data type as A.


[1] Lindbloom, Bruce. Chromatic Adaptation.

Introduced in R2017b

Was this topic helpful?