measureColor
Measure color reproduction using test chart
Syntax
Description
esfrChart
or colorChecker
Object
Use an esfrChart
or a colorChecker
object when
you want to automatically detect the color regions of interest (ROIs) of a test
chart. The esfrChart
object supports the Enhanced or Extended
version of the Imatest® eSFR test chart [1]. The
esfrChart
object supports the Calibrite ColorChecker® Classic test chart [2].
measures the color values at all color ROIs of an Imatest eSFR test chart or a Calibrite ColorChecker Classic test chart.colorValues
= measureColor(chart
)
[
also returns a color correction matrix computed using a linear least squares
fit.colorValues
,colorCorrectionMatrix
] = measureColor(chart
)
Test Chart Image (since R2024a)
Use a test chart image for other types of test charts that are not supported by
the esfrChart
or colorChecker
objects. You must
identify the positions of the color ROIs.
measures the color values at all color ROIs at positions
colorValues
= measureColor(im
,roiPositions
,refLAB
)roiPositions
for test chart image
im
. The reference L*a*b* values of each ROI are given
by refLAB
.
optionally specifies the color space and white point using name-value
arguments.colorValues
= measureColor(im
,roiPositions
,refLAB
,Name=Value
)
[
also returns a color correction matrix computed using a linear least squares
fit, using any combination of input arguments from previous syntaxes.colorValues
,colorCorrectionMatrix
] = measureColor(___)
Examples
Measure Color Accuracy of eSFR Chart
Read an image of an eSFR chart into the workspace.
I = imread("eSFRTestImage.jpg");
Create an esfrChart
object, then display the chart with ROI annotations. The 16 color patch ROIs are labeled with white numbers.
chart = esfrChart(I);
displayChart(chart,displayEdgeROIs=false, ...
displayGrayROIs=false,displayRegistrationPoints=false)
Measure the color in all color patch ROIs.
colorTable = measureColor(chart)
colorTable=16×8 table
ROI Measured_R Measured_G Measured_B Reference_L Reference_a Reference_b Delta_E
___ __________ __________ __________ ___________ ___________ ___________ _______
1 67 57 58 38.586 7.541 7.0812 15.15
2 156 127 122 62.182 13.225 13.826 9.8745
3 73 95 152 49.369 -0.51463 -20.062 18.455
4 62 79 58 43.926 -6.8587 17.278 14.849
5 104 109 171 53.415 9.457 -22.822 12.99
6 118 175 187 69.95 -20.889 -0.21752 13.123
7 214 192 69 78.643 1.8052 67.091 9.2399
8 154 73 138 46.853 41.998 -17.056 5.1282
9 62 120 182 51.05 -15.166 -22.416 22.813
10 55 80 185 40.811 8.7346 -44.265 22.782
11 79 135 72 55.716 -23.419 28.839 9.4826
12 152 53 77 42.759 44.167 7.9536 5.4168
13 169 91 52 58.211 27.58 47.578 15.988
14 142 63 87 47.012 39.15 8.5453 11.651
15 91 67 102 40.591 17.951 -9.525 10.897
16 152 183 80 70.505 -16.318 49.811 10.253
Display the color accuracy measurements. Each square color patch is the measured color, and the thick surrounding border is the reference color for that ROI. Each color accuracy measurement is displayed as Delta_E
, the Euclidean distance between measured and reference colors in the CIE 1976 L*a*b* color space. More accurate colors have a smaller Delta_E
.
figure displayColorPatch(colorTable)
For an alternative representation of the color accuracy measurements, plot the measured and reference colors in the CIE 1976 L*a*b* color space on a chromaticity diagram. Red circles indicate the reference color. Green circles indicate the measured color of each color patch. The chromaticity diagram does not portray the brightness of color.
figure plotChromaticity(colorTable)
ROIs with a shorter distance between the reference and measurement points have smaller differences in chromaticity, which can contribute to a smaller value of Delta_E
. However, brightness also contributes to the value of Delta_E
. For example, even though the reference and measurement points for ROI 13 are near each other on the chromaticity diagram, they have a large Delta_E
because of their large difference in brightness.
Measure Color of ColorChecker Chart
Read an image of a ColorChecker® chart into the workspace.
I = imread("colorCheckerTestImage.jpg");
Create a colorChecker
object, then display the chart with ROI annotations.
chart = colorChecker(I); displayChart(chart)
Measure the color in each color patch ROI.
colorTable = measureColor(chart)
colorTable=24×9 table
ROI Color Measured_R Measured_G Measured_B Reference_L Reference_a Reference_b Delta_E
___ ________________ __________ __________ __________ ___________ ___________ ___________ _______
1 {'DarkSkin' } 160 129 120 37.54 14.37 14.92 20.193
2 {'LightSkin' } 229 200 191 64.66 19.27 17.5 22.587
3 {'BlueSky' } 146 191 241 49.32 -3.82 -22.54 27.312
4 {'Foliage' } 130 161 117 43.46 -12.74 22.72 20.404
5 {'BlueFlower' } 175 187 248 54.94 9.61 -24.79 23.073
6 {'BluishGreen' } 155 232 226 70.48 -32.26 -0.37 18.284
7 {'Orange' } 255 161 99 62.73 35.83 56.5 16.114
8 {'PurplishBlue'} 130 164 254 39.43 10.75 -45.17 28.889
9 {'ModerateRed' } 252 146 160 50.57 48.64 16.67 23.601
10 {'Purple' } 139 118 175 30.1 22.54 -20.87 24.672
11 {'YellowGreen' } 187 226 110 71.77 -24.13 58.19 15.21
12 {'OrangeYellow'} 241 194 76 71.51 18.24 67.37 14.148
13 {'Blue' } 96 131 255 28.37 15.42 -49.8 33.34
14 {'Green' } 118 209 130 54.38 -39.72 32.27 22.461
15 {'Red' } 234 116 114 42.43 51.05 28.62 21.87
16 {'Yellow' } 241 227 105 81.8 2.67 80.41 23.495
⋮
Measure Color of Custom Test Chart
Read and display an image of a custom test chart with color patch ROIs. This example simulates a custom test chart image by cropping an Imatest eSFR test chart.
I = imread("RGBColorPatches.jpg");
imshow(I)
Draw ROIs for the red, green, and blue color patches.
numROIs = 3; roiPos = zeros(numROIs,4); for cnt = 1:numROIs hrect = drawrectangle; roiPos(cnt,:) = hrect.Position; end
Load the reference L*a*b* values of the color patches, which are saved in a file called RGBColorPatches_refLab.mat
. The white point of the reference values is the CIE standard illuminant D50.
load("RGBColorPatches_refLab.mat");
Calculate the color reproduction values for these selected edges, specifying the white point.
colorValues = measureColor(I,roiPos,refLab,ReferenceLABWhitePoint="d50");
On a color patch diagram, display the measured and reference colors and the color error.
displayColorPatch(colorValues)
Input Arguments
chart
— Test chart
esfrChart
object | colorChecker
object
Test chart, specified as an esfrChart
object or a colorChecker
object.
im
— Test chart image
RGB image
Since R2024a
Test chart image, specified as an RGB image.
Data Types: single
| double
| uint8
| uint16
roiPositions
— ROI positions
n-by-4 numeric matrix
Since R2024a
ROI positions, specified as an n-by-4 numeric matrix, where n is the number of ROIs.
refLAB
— Reference L*a*b* values
n-by-3 numeric array
Since R2024a
Reference L*a*b* values for each of the selected ROIs, specified as an n-by-3 numeric matrix, where n is the number of ROIs.
Data Types: single
| double
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: colorValues =
measureColor(im,roiPositions,refLAB,InputColorSpace="adobe-rgb-1998")
specifies the Adobe RGB 1998 color space.
InputColorSpace
— Input color space
"srgb"
(default) | "adobe-rgb-1998"
| "prophoto-rgb"
ReferenceLABWhitePoint
— White point
"d65"
(default) | 1-by-3 numeric vector
Since R2024a
White point used for the reference L*a*b* values, specified as a
1-by-3 numeric vector or one of the CIE standard illuminants listed in
the table. You can specify this name-value argument only when you use a
test chart image, im
.
Value | White Point |
---|---|
"a" | CIE standard illuminant A, |
"c" | CIE standard illuminant C, [0.9807, 1.0000, 1.1822] . Simulates average or
north sky daylight with correlated color temperature of 6774 K. Deprecated by
CIE. |
"e" | Equal-energy radiator, [1.000, 1.000, 1.000] . Useful as a theoretical
reference. |
"d50" | CIE standard illuminant D50, [0.9642, 1.0000, 0.8251] .
Simulates warm daylight at sunrise or sunset with correlated color
temperature of 5003 K. Also known as horizon light. |
| CIE standard illuminant D55, |
"d65" | CIE standard illuminant D65, [0.9504, 1.0000, 1.0888] . Simulates noon
daylight with correlated color temperature of 6504 K. |
"icc" | Profile Connection Space (PCS) illuminant used in ICC profiles. Approximation of
[0.9642, 1.000, 0.8249] using fixed-point, signed, 32-bit
numbers with 16 fractional bits. Actual value: [31595,32768,
27030]/32768 . |
If you specify
chart
as anesfrChart
object, then themeasureColor
function uses the CIE standard illuminant D65.If you specify
chart
as acolorChecker
object, then themeasureColor
function uses the CIE standard illuminant D50. The reference L*a*b* values are for the "After November 2014" version of the ColorChecker chart.
Output Arguments
colorValues
— Color values
table
Color values in each color patch ROI, returned as a table. The table has one row for each measured ROI. The table always has these variables (columns):
Variable | Description |
---|---|
ROI | Index of the sampled ROI. |
Measured_R | Mean value of red channel pixels in the ROI.
|
Measured_G | Mean value of green channel pixels in the ROI.
|
Measured_B | Mean value of blue channel pixels in the ROI.
|
Reference_L | Reference L* value of the ROI.
|
Reference_a | Reference a* value of the ROI.
|
Reference_b | Reference b* value of the ROI.
|
Delta_E | Euclidean color distance between the measured
and reference color values in the L*a*b* color
space. If
you specify a test chart object
|
If you specify a test chart image im
,
then the table has this additional variable:
Variable | Description |
---|---|
ROIPositions | Position of the ROI, returned as a 4-element vector
of the form [X Y Width Height] .
X and Y are
the coordinates of the top-left corner of the ROI.
Width and
Height are the width and height
of the ROI, in pixels. |
For more information on accessing the measurements within the table, see Access Color Measurements.
colorCorrectionMatrix
— Color correction coefficients
4-by-3 matrix
Color correction coefficients, returned as a 4-by-3 matrix.
colorCorrectionMatrix
represents an affine
transformation that you can use to color-correct images that are captured
under similar lighting conditions as the test chart image. For an example,
see Correct Colors Using Color Correction Matrix.
If you specify a test chart image im
, then the
measureColor
function calculates the color
correction matrix in linear color space.
Data Types: double
More About
Access Color Measurements
The order of the variables in the color table depends on whether you input a test
chart image, im
, or a chart object, chart
.
If you need to access variables of the color table, refer to variable names and not
numeric indices.
For example, to access the Delta_E
variable of the color table,
use code such as this.
deltaE = colorValues.Delta_E;
For another example, to access the measured RGB values of the ROI with index 3,
use code such as this. The first command returns the Measured_R
,
Measured_G
, and Measured_B
variables in a
table for the ROI with index 3. The second command converts the table into a numeric
row vector.
measuredRGB3 = colorValues(colorValues.ROI==3,["Measured_R" "Measured_G" "Measured_B"]) measuredRGB3vec = measuredRGB3{1,:};
Note that you can perform these two operations in a single command:
measuredRGB3vec = colorValues{colorValues.ROI==3,["Measured_R" "Measured_G" "Measured_B"]}
For more information, see Access Data in Tables and Access Data in Cell Arrays.
References
[1] Imatest. "Esfr". https://www.imatest.com/mathworks/esfr/.
[2] Calibrite. "ColorChecker Classic". https://calibrite.com/us/product/colorchecker-classic/.
Version History
Introduced in R2017bR2024a: Support for additional test charts
You can now measure the color reproduction of color ROIs for test charts other than the Imatest Enhanced or Extended eSFR test chart and the Calibrite ColorChecker Classic test chart.
To measure the color of additional types of test charts, specify the test chart
image, im
, the position of the color patch ROIs,
roiPositions
, and the reference L*a*b* values,
refLAB
.
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)