Advanced Functions
Color match for CIE Standard Observer
The colormatch()
function returns an XYZ color corresponding to a wavelength specified in nanometers.
colormatch(wavelen::Real)
The CIE defines a standard observer, defining a typical frequency response curve for each of the three human eye cones.
For instance, conversion from optical wavelength to RGB can be achieved with:
RGB.(colormatch.(350:10:750))
Colors.colormatch
— Functioncolormatch(wavelength)
colormatch(matchingfunction, wavelength)
Evaluate the CIE standard observer color match function.
Arguments
matchingfunction
(optional): a type used to specify the matching function. Choices include:CIE1931_CMF
(the default, the CIE 1931 2° matching function)CIE1964_CMF
(the CIE 1964 10° color matching function)CIE1931J_CMF
(Judd adjustment toCIE1931_CMF
)CIE1931JV_CMF
(Judd-Vos adjustment toCIE1931_CMF
)CIE2006_2_CMF
(transformed from the CIE 2006 2° LMS cone fundamentals)CIE2006_10_CMF
(transformed from the CIE 2006 10° LMS cone fundamentals)
wavelength
: Wavelength of stimulus in nanometers.
Returns the XYZ value of perceived color.
As of February 2020, only CIE1931_CMF
and CIE1964_CMF
have been standardized by the ISO/CIE. CIE2006_2_CMF
and CIE2006_10_CMF
are proposals which have yet to be ratified by the CIE, even though they are sometimes referred to as CIE 2012 CMFs.
Chromatic Adaptation (white balance)
The whitebalance()
function converts a color according to a reference white point.
whitebalance{T <: Color}(c::T, src_white::Color, ref_white::Color)
Convert a color c
viewed under conditions with a given source whitepoint src_whitepoint
to appear the same under different conditions specified by a reference whitepoint ref_white
.
Colors.whitebalance
— Functionwhitebalance(c, src_white, ref_white)
Whitebalance a color.
Input a source (adopted) and destination (reference) white. For example, if you want a photo taken under fluorescent lighting to appear correct in regular sunlight, you might do something like whitebalance(c, WP_F2, WP_D65)
.
Arguments
c
: An observed color.src_white
: Adopted or source white corresponding toc
ref_white
: Reference or destination white.
Returns a whitebalanced color.
Simulation of color deficiency ("color blindness")
Three functions are provided that map colors to a reduced gamut to simulate different types of dichromacy, the loss of one of the three types of human photopigments.
Protanopia, deuteranopia, and tritanopia are the loss of long, middle, and short wavelength photopigment, respectively.
These functions take a color and return a new, altered color in the same colorspace.
protanopic(c::Color, p::Float64)
deuteranopic(c::Color, p::Float64)
tritanopic(c::Color, p::Float64)
Also provided are versions of these functions with an extra parameter p
in [0, 1]
, giving the degree of photopigment loss, where 1.0
is a complete loss, and 0.0
is no loss at all. The partial loss simulates the anomalous trichromacy, i.e. protanomaly, deuteranomaly and tritanomaly.
Colors.protanopic
— Functionprotanopic(c)
protanopic(c, p)
Convert a color to simulate protanopic color deficiency (lack of the long-wavelength photopigment). c
is the input color; the optional argument p
is the fraction of photopigment loss, in the range 0 (no loss) to 1 (complete loss).
Colors.deuteranopic
— Functiondeuteranopic(c)
deuteranopic(c, p)
Convert a color to simulate deuteranopic color deficiency (lack of the middle-wavelength photopigment). See protanopic
for detail about the arguments.
Colors.tritanopic
— Functiontritanopic(c)
tritanopic(c, p)
Convert a color to simulate tritanopic color deficiency (lack of the short-wavelength photopigment). See protanopic
for detail about the arguments.
Most saturated color
The MSC(h)
function returns the most saturated color for a given hue h
(defined in LCHuv space, i.e. in range [0, 360]). Optionally the lightness l
can also be given, as MSC(h, l)
. The function calculates the color by finding the edge of the LCHuv space for a given angle (hue).
Colors.MSC
— FunctionMSC(h)
MSC(h, l; linear=false)
Calculate the most saturated color in sRGB gamut for any given hue h
by finding the corresponding corner in LCHuv space. Optionally, the lightness l
may also be specified.
Arguments
h
: Hue [0,360] in LCHuv spacel
: Lightness [0,100] in LCHuv space
Keyword arguments
linear
: If true, the saturation is linearly interpolated between black/ white andMSC(h)
as the gamut is approximately triangular in L-C section.
MSC(h)
returns an LCHuv
color, but MSC(h, l)
returns a saturation value. This behavior might change in a future release.