deltaE
Description
Examples
Calculate Color Difference of Two Colors using CIE76 Standard
Specify two RGB color values.
pureRed = uint8([255 0 0]); darkRed = uint8([255 10 50]);
Calculate the color difference of the colors.
dE = deltaE(pureRed,darkRed)
dE = single
18.6206
Calculate Color Difference of RGB Images
Read a color image into the workspace.
I1 = imread('peppers.png');
imshow(I1)
Alter the local color contrast in the image.
I2 = localcontrast(I1); imshow(I2)
Calculate the color difference of the images.
dE = deltaE(I1,I2);
Display the color difference as an image. The maximum value of dE
exceeds the range [0, 1] expected of images of data type single
, so display the image using the full display range of the data. Bright pixels indicate a large color difference and therefore a larger amount of contrast enhancement.
imshow(dE,[])
Calculate Color Difference of L*a*b* Images
Read and display an image of tissue stained with hematoxylin and eosin (H&E).
he = imread("hestain.png");
imshow(he)
Convert the image to the L*a*b* color space.
lab = rgb2lab(he);
Make a copy of the image, then increase the signal of the a* channel. Red tones in the image become more saturated while the image overall brightness and the blue tones are unchanged.
lab2 = lab; scaleFactor = 1.2; lab2(:,:,2) = scaleFactor*lab(:,:,2);
Calculate the color difference of the original and enhanced image in the L*a*b* color space.
dE = deltaE(lab,lab2,isInputLab=true);
Display the color difference as an image. Scale the display range to match the range of pixel values in dE
. Bright regions indicate the greatest color difference and correspond with the pink regions of tissue.
imshow(dE,[])
Input Arguments
I1
— First set of color data
1-by-3 numeric vector | c-by-3 numeric matrix | numeric array
First set of color data, specified in one of these formats.
A 1-by-3 numeric vector representing a reference color.
A c-by-3 numeric matrix representing a set of c colors.
An m-by-n-by-3 numeric array representing a color image.
A multidimensional numeric array, such as an m-by-n-by-3-by-p array, representing a batch of color images. The third dimension must correspond to the color channel and have 3 channels.
If I2
is not a reference color, then I1
must be either a reference color or a numeric array of the same size as
I2
.
I1
and I2
must be in the same color space.
By default, the deltaE
function expects that
I1
and I2
are in the sRGB color space. If
I1
and I2
are instead in the L*a*b* color
space, then specify the isLab
argument as true
.
L*a*b* color values can be of data type single
or
double
only.
Data Types: single
| double
| uint8
| uint16
I2
— Second set of color data
1-by-3 numeric vector | c-by-3 numeric matrix | numeric array
Second set of color data, specified in one of these formats.
A 1-by-3 numeric vector representing a reference color.
A c-by-3 numeric matrix representing a set of c colors.
An m-by-n-by-3 numeric array representing a color image.
A multidimensional numeric array, such as an m-by-n-by-3-by-p array, representing a batch of color images. The third dimension must correspond to the color channel and have 3 channels.
If I1
is not a reference color, then I2
must be either a reference color or a numeric array of the same size as
I1
.
I1
and I2
must be in the same color space.
By default, the deltaE
function expects that
I1
and I2
are in the sRGB color space. If
I1
and I2
are instead in the L*a*b* color
space, then specify the isLab
argument as true
.
L*a*b* color values can be of data type single
or
double
only.
Data Types: single
| double
| uint8
| uint16
isLab
— Color values are in L*a*b* color space
false
or 0
(default) | true
or 1
Color values are in the L*a*b* color space, specified as a numeric or
logical 0
(false
) or 1
(true
).
Output Arguments
dE
— Color difference
numeric matrix | c-by-1 column vector | numeric scalar | numeric array
Color difference (delta E), returned as one of the following.
An m-by-n numeric matrix. The array represents the pixel-wise color difference between two color images, or between a color image and a reference color.
A c-by-1 numeric column vector. The vector represents the color difference between two sets of c colors, or between a set of c colors and a reference color.
A numeric scalar that represents the color difference between two reference colors.
A multidimensional numeric array. The array represents the pixel-wise color difference between two batches of color images, or between a batch of color images and a reference color. The third dimension has length 1 and indicates the color difference.
If I1
or I2
is of data type
double
, then dE
is of data type
double
. Otherwise, dE
is of data type
single
.
Data Types: single
| double
Tips
To improve the accuracy of the color difference calculation, use the
imcolordiff
function. This function follows the CIE94 and CIEDE2000 standards and offers parameters to improve perceptual uniformity for different applications.
Version History
Introduced in R2020bR2023a: Support for reference colors and multidimensional images
You can now calculate the color difference between each pixel in an image (or each color
in a set of colors) and a reference color. To do this, specify either
I1
or I2
as a 1-by-3 numeric vector that
represents the reference color.
You can now specify I1
and I2
as
multidimensional numeric arrays representing batches of color images.
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)