Playing with Colors

Giulio Alessandrini, WRI

Join the Conversation #WolframTechConf

ABSTRACT

For many years, the Wolfram Language has been striving to offer a comprehensive color-processing system that is easy to use and well integrated with the rest of the language. Its applications range from teaching color theory to recoloring and correcting images, from visualizing and comparing color gamuts to color-based image segmentation. Using examples from all these topics—and more—we are going to give an overview of how you can use the current Wolfram Language color-processing capabilities, what can be built upon that and how one can have fun playing with colors.

What is a color?

Image[RandomColor[{5,5}],ImageSize->400]

What is a color?

There’s a light

What we usually call colors are the effect of the electromagnetic radiation that is emitted by radiating objects (like a light bulb or the sun) or reflected by “dark” objects (like almost all everyday objects). This radiation is compose by myriads of photons, particles that move at constant speed and carry energy proportional to their frequency according to the formula

QuantityVariable["E","Energy"]==Quantity[1,"PlanckConstant"] QuantityVariable["ν","Frequency"]

Manipulate[
Plot[
Sin[ω x],{x,0,2Pi},
PlotStyle->{ColorData["VisibleSpectrum"][Rescale[1/ω,{1/30,1},{480,680}]],Thickness[.015]},
Ticks->None,AxesLabel->{"ν",None},PlotPoints->50,MaxRecursion->6
],
{{ω,5},2^Range[0,5,.1],ControlType->Slider}]

What is a color?

There’s a light

The portion of these photons that can be perceived by our eyes is usually called light and the property that we call color is dependant on the photon energy, thus its frequency. Very often we deal with the wavelength of the photons so it’s very useful to know its relation to the frequency:

QuantityVariable["λ","Length"]==Quantity["SpeedOfLight"] /QuantityVariable["ν","Frequency"]

Now we can understand a bit better an image like this (the wavelength is expressed in nanometers—(10^(-9)) meters):

Labeled[BarLegend["VisibleSpectrum",LegendLayout->"Row",LegendLabel->"VisibleSpectrum",ImageSize->700,LabelStyle->18],Text[Style[#,14]]&@"λ [nanometers]",Right]

A simple experiment is to use a prism to divide white light among its components, making apparent the different colors that compose the white light:

What is a color?

(not so black)body

Any object emits light according to its temperature:

formula=FormulaData[{"PlanckRadiationLaw","Wavelength"},{"T"->Quantity[T,"Kelvins"],"λ"->Quantity[λ,"Nanometers"]}][[3,2]];
B[T_,λ_]=formula

Manipulate[
Plot[B[T,λ],{λ,100,3000},
ScalingFunctions->{"Linear","Log"},PlotRange->{10^1, 10^16},ImageSize->Large,Frame->True,FrameLabel->{Quantity["","Nanometers"],Quantity["","Watts"/("Meters"^3*"Steradians")]},
ColorFunction->Function[ColorData["VisibleSpectrum"][#]],
ColorFunctionScaling->False,
PlotStyle->Thickness[.02],
Epilog->{ColorData["BlackBodySpectrum"][T],EdgeForm[Black],Disk[{2600,Log[5 10^14]},Offset[20]],Text[Style["T = "<>ToString[T]<>"K",Black,16],{2700,Log[3 10^13]}]}
],
{T,1000,10000,500}
]

What is a color?

The color of the sky

Let’s work at our sun’s temperature

sunT=(Entity["Sun", Entity["Star","Sun"], "Entity[\"Star\", \"Sun\"]", "star"])[(EntityProperty["effective temperature", EntityProperty["Star","EffectiveTemperature"], "EntityProperty[\"Star\", \"EffectiveTemperature\"]"])]

B[λ_]=B[QuantityMagnitude@sunT,λ]

What’s the average frequency?

norm=NIntegrate[B[λ],{λ,100,100000}];
meanλ=NIntegrate[B[λ]λ,{λ,100,100000}]/norm

Image[ColorData["VisibleSpectrum"][meanλ]]

We can try to find what’s the average frequency in the visible range (390mn, 700nm)

norm=NIntegrate[B[λ],{λ,390,700}];
meanλ=NIntegrate[B[λ]λ,{λ,390,700}]/norm

Image[ColorData["VisibleSpectrum"][meanλ]]

What’s the color of the sky?

The color of the sky

We forgot about Rayleigh scattering!

Plot[{B[λ]/(1.7 10^10),B[λ]/λ^4},{λ,100,1500},PlotRange->All,PlotLegends->{"~ B[λ]","~ B[λ]/λ^4"},LabelStyle->14,Ticks->{True,False}]

norm=NIntegrate[B[λ]/λ^4,{λ,390,700}];
meanλ=NIntegrate[λ B[λ]/λ^4,{λ,390,700}]/norm

Image[ColorData["VisibleSpectrum"][meanλ]]

But our eyes do not see the same at all frequencies

norm=NIntegrate[B[λ]/λ^4,{λ,390,700}];
x=NIntegrate[B[λ]/λ^4 xbar[λ],{λ,390,700}]/norm;
y=NIntegrate[B[λ]/λ^4 ybar[λ],{λ,390,700}]/norm;
z=NIntegrate[B[λ]/λ^4 zbar[λ],{λ,390,700}]/norm;
Image[XYZColor[x,y,z]]

What’s the color of the sky?

Back to the black body

We can use the same method to compute the chromaticity of a black body

planckianLoci=Table[
norm=NIntegrate[B[T,λ],{λ,390,700}];
x=NIntegrate[B[T,λ] xbar[λ],{λ,390,700}]/norm;
y=NIntegrate[B[T,λ] ybar[λ],{λ,390,700}]/norm;
z=NIntegrate[B[T,λ] zbar[λ],{λ,390,700}]/norm;
XYZColor[x,y,z],{T,100 2^Range[3,8,.2]}
]//Quiet

ChromaticityPlot[planckianLoci,PlotStyle->PointSize[.04],PlotLabel->"Planckian Loci"]

Color correction

My white is better than yours

Changing the chromaticity of the color has a similar effect to changing the temperature of the light illuminating the scene

Manipulate[
HighlightImage[ColorBalance[i,Automatic->(Quantity[T, "K", kelvins, "Kelvins"])],{Opacity[.9],ColorData["BlackBodySpectrum"][T],Disk[Scaled[{.85,.85}],20]}],{{T,6500},4000,10000},
Initialization:>{i=Import["https://cdn.pixabay.com/photo/2016/09/16/21/40/winter-1675197_1280.jpg",ImageSize->400]},
SaveDefinitions->True
]

How can we see?

Human vision

Our eyes use two different kind of cells to detect incoming particles: the cones and the rods. As the rods play are important mainly in low light condition and are not involved in color perception, let’s focus on the cones.

In order to perceive differently photons at different wavelength we need at least two receptors the receive in different areas of the spectrum. Human beings have indeed three type of cones that are sensible to short (S), medium (M), and long wavelength (L).

{λ,L,M,S}=lmsTable;
centered@ListLinePlot[{S,M,L},DataRange->MinMax@λ,PlotLegends->{"S(hort)","M(edium)","L(ong)"},
PlotLabel->"Cone cell sensitivities",PlotStyle->Thickness[.006],LabelStyle->16,ImageSize->600,Epilog->{Raster[{List@@@ColorData["VisibleSpectrum"]/@λ},{{Min[λ],-.01},{Max[λ],.012}}]}]

How can we see?

Intermission: color blindness

Damage or alteration to the eye cells are the main responsible for color blindness.

A fault in the development of one of the cones causes a condition called dichromacy (“di” meaning “two” and chroma meaning “color”) and, depending on the affected receptor, there are three possible dichromacy condition: protanopia, deuteranopia, tritanopia.

image=;

Row[Labeled[ImageEffect[Image[image,ImageSize->300],{"ColorBlindness",#}],Text[#]]&/@{"Protanopia","Deuteranopia","Tritanopia"},Spacer[10]]

Color representation

RGB

The discovery of the cone cells helped a great deal in explaining why we perceive the world in colors but the cone sensitivity is not a great representation of the colors. A new set of coordinated was developed, based on three monochromatic lights 700 nm (red), 546.1 nm (green) and 435.8 nm (blue).

{λ,rbar,gbar,bbar}=rgbTable;
ListLinePlot[{rbar,gbar,bbar},DataRange->MinMax@λ,PlotLegends->{"r(λ)","g(λ)","b(λ)"},PlotLabel->"RGB color matching functions",PlotStyle->{Red,Green,Blue},PlotRange->All,AxesLabel->{"nm",None},BaseStyle->Thickness[.006],LabelStyle->16,ImageSize->600,InterpolationOrder->3]

{R,G,B} can be seen as a set of coordinates in a three-dimensional space

ChromaticityPlot3D["RGB","RGB"]

Color representation

The CIE XYZ color space

Some of the requirement for the new functions:

Have one component equal to the perceived brightness at a given wavelength

Generate the same components on a constant energy white point (same energy at all wavelength)

Be everywhere greater than or equal to zero

ListLinePlot[{rbar,gbar,bbar},DataRange->MinMax@λ,PlotLegends->{"(OverBar[r])(λ)","(OverBar[g])(λ)","(OverBar[b])(λ)"},PlotLabel->"RGB color matching functions (zoom)",PlotStyle->{Red,Green,Blue},AxesLabel->{"nm",None},PlotRange->{-.1,.1},InterpolationOrder->3,LabelStyle->14,ImageSize->400]

Color representation

The CIE XYZ color space

The new CIE XYZ functions were defined to address those concerns.

Plot[{xbar[λ],ybar[λ],zbar[λ]},{λ,390, 750},
PlotLegends->{"x(λ)","y(λ)","z(λ)"},
AxesLabel->{"nm",None},
PlotRange->All,
PlotLabel->"XYZ color matching functions",PlotRange->All,AxesLabel->{"nm",None},PlotStyle->Thickness[.006],LabelStyle->16,ImageSize->600
]

The former RGB cube under the linear transformation to the XYZ space:

ChromaticityPlot3D["RGB","XYZ",BoxRatios->Automatic]

Color representation

The chromaticity diagram

As the luminance Y represents the perceived brightness, plane of constant Y contains all the possible chromaticities at a given brightness.
To capitalize on this fact, one can define scaled chromaticity coordinates:

x=(X/(X+Y+Z))
y=(Y/(X+Y+Z))
z=(Z/(X+Y+Z))

ChromaticityPlot3D["RGB","CIE31",BoxRatios->Automatic]

Color representation

The chromaticity diagram

As only two of the three chromaticity coordinates are independent, ad 2D representation of the chromaticity is possible.

ChromaticityPlot["CIERGB",{"CIE31",0},BoundaryStyle->Black,PlotTheme->"Detailed",Appearance->{"FilledVisibleSpectrum","Wavelengths"->True}]

Color representation

Not just one RGB

Different kind of RGB spaces are defined specifying different chromaticities for the three primaries (red, green, blue).

ChromaticityPlot[{"AdobeRGB","AppleRGB","CIERGB","ProPhotoRGB","sRGB","WideGamutRGB"},{"CIE31",0},PlotTheme->"Detailed",Appearance->{"FilledVisibleSpectrum","Wavelengths"->True}]

ChromaticityPlot3D[{"AdobeRGB","AppleRGB","CIERGB","ProPhotoRGB","sRGB","WideGamutRGB"},"LAB",BoxRatios->Automatic]

Color representation

Experiment: color mixing

This image is composed by a green and a red part

i=ImageAssemble[ConstantImage/@{Green,Red}]

now we perform a simple linear interpolation in the horizontal direction

MeanFilter[i,{0,150}]

Why is the middle is so dark? Shouldn’t it be a smooth transition between Red and Green?

Color representation

Experiment: color mixing

This is because there are only so many number available to represent a color and human vision is better at detecting small differences in brightness among dark colors than bright colors.
So instead of coding the brightness linearly it is encoded after performing a compression of the kind

x|->(x^(1/γ))

centered@Legended[GraphicsRow[{
Plot[{x,x^(1/2.2)},{x,0,1},PlotStyle->{Black,Red},AspectRatio->1,LabelStyle->14,AxesLabel->{"Brightness","PixelValue"},PlotLabel->"Encoding"],
Plot[{x,x^(2.2)},{x,0,1},PlotStyle->{Black,Red},AspectRatio->1,LabelStyle->14,AxesLabel->{"PixelValue","Brightness"},PlotLabel->"Decoding"]
}],LineLegend[{Black, Red},{"normal","compressed"}]]

The appearance of a uniform scale of gray shades under different compression factors

Manipulate[
Framed[
Labeled[Graphics[Table[{GrayLevel[i^(γ/2.2)],Rectangle[{10i,0}]},{i,0,1,1/10}],AspectRatio->1/5,ImageSize->Full],Style[Row[{"γ = ",γ}],20]],
Background->Dynamic[If[Abs[γ-2.2]<.1,LightRed,LightBlue]]
],
{{γ,1},.1,3,.1}
]

Color representation

Experiment: color mixing

If we want to average the color with their proper brightness we have to convert the image to a linear space, like XYZ

ColorConvert[MeanFilter[ColorConvert[i,"XYZ"],{0,150}],"RGB"]

Color representation

Experiment: color mixing

The relationship between two colors is deeply influenced by the color model that is used to describe them.
The function Blend performs a color mixing in the colors native space thus preserving its natural metric and its characteristics.

Row[{
Column[Prepend[Labeled[ArrayPlot[{Table[Blend[ColorConvert[{Green,Red},#],n],{n,0,1,.01}]},AspectRatio->.25,Frame->None,ImageSize->Medium],Text[Style[ToString@#,16]]]&/@
{Hue,RGBColor,XYZColor},Style[Inactivate[Blend[ColorConvert[{Green,Red},space],color]],18,"CodeText"]],Alignment->Center],
ChromaticityPlot3D[{
MeanFilter[ColorConvert[i,"RGB"],{0,150}],
MeanFilter[ColorConvert[i,"XYZ"],{0,150}],
Quiet@MeanFilter[ColorConvert[i,"HSB"],{0,150}],
"RGB"
},"XYZ",PlotStyle->PointSize[.02],FillingStyle->Opacity[.2],ViewPoint->Bottom,ImageSize->350]
},Spacer[40]]

Color correction

Custom color curves

Different non linear functions can be used to create specific color effects

Color representation

Color opponencies

While the properties of XYZ make it very useful for computing color combinations and makes it the space of choice as a color conversion hub, it’s not a good representation of how human being perceive colors. To better capture the perceptual properties of the colors, other spaces—such as LAB—have been defined.

img=ColorConvert[Import["https://pixabay.com/static/uploads/photo/2015/10/15/22/37/color-990167_960_720.jpg",ImageSize->240],"LAB"];
Row[{Graph[MapThread[Property[#1,{VertexShape->#2,VertexSize->1.1,VertexLabels->Placed[#3,{.85,.5}]}]&,
{
Range[4],
{img,ImageMultiply[img,{1,0,0}],ImageMultiply[img,{1,1,0}],ImageMultiply[img,{1,0,1}]},
{"","(SuperStar[L])","(SuperStar[a])","(SuperStar[b])"}
}],
MapThread[
Property[#,EdgeShapeFunction->Function[x,Arrow[x,#2]]]&,
{Thread[1->{2,3,4}],{1.4,1.1,1.4}}
],EdgeStyle->Black,
VertexCoordinates->{{0,0},{3,2},{3,0},{3,-2}},
ImageSize->500,EdgeShapeFunction->None,VertexLabelStyle->14,PlotRange->{{-1.1,4.8},{-2.7,2.7}}],ChromaticityPlot3D[img,"LAB",ImageSize->500,BoxRatios->Automatic]},Spacer[20]]

Color correction

The space matters

When correcting for a color property (e.g. oversaturation) the working color space has a deep impact on the final result.

Reducing the contrast in RGB has a completely different effect then operating on the HSB saturation or the chroma channel in LCH:

flower=ImageResize[Import["http://pixabay.com/static/uploads/photo/2015/06/02/11/36/poppy-794937_640.jpg"],300];
Row[{
Manipulate[ImageAdjust[flower,contrast],{{contrast,0},-1,1},SaveDefinitions->True],
Manipulate[ImageMultiply[ColorConvert[flower,"HSB"],{1,saturation,1}],{{saturation,1},0,2},SaveDefinitions->True],
Manipulate[ImageMultiply[ColorConvert[flower,"LCH"],{1,chroma,1}],{{chroma,1},0,2},SaveDefinitions->True]
}]

Color correction

Changing a color - find what you need

plot=;

ChromaticityPlot3D[{plot, ColorsNear[Red,.4],ColorsNear[Green,.4]},"LAB",BoxRatios->Automatic]

{ColorDetect[plot,ColorsNear[Red,.4]],ColorDetect[plot,ColorsNear[Green,.4]]}

Color correction

Changing a color - just do it

ImageRecolor[plot,{Red->,Green->},MaxColorDistance->.4,Method->"Hue"]

Thank you

Material

Utilities

centered[expr_]:=CellPrint@Cell[
BoxData@ToBoxes[expr],
"Output",
TextAlignment->Center
]

Data

lmsTable=
{{390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830},{0.000415003`,0.00050265`,0.000607367`,0.00073185`,0.000879012`,0.00105192`,0.00125373`,0.00148756`,0.00175633`,0.00206261`,0.00240836`,0.00279522`,0.0032264`,0.00370617`,0.00423972`,0.00483339`,0.00549335`,0.00621933`,0.00700631`,0.00784503`,0.00872127`,0.00961879`,0.0105324`,0.011462`,0.0124105`,0.0133837`,0.014387`,0.0154116`,0.0164424`,0.0174614`,0.018448`,0.0193852`,0.0202811`,0.0211545`,0.0220286`,0.0229317`,0.0238896`,0.0249026`,0.0259631`,0.0270619`,0.0281877`,0.0293303`,0.0304898`,0.0316694`,0.0328731`,0.0341054`,0.035367`,0.03664`,0.0378988`,0.0391148`,0.0402563`,0.0412989`,0.0422582`,0.0431627`,0.0440444`,0.044938`,0.0458729`,0.0468459`,0.0478446`,0.0488555`,0.0498639`,0.0508618`,0.0518731`,0.0529317`,0.0540746`,0.0553418`,0.0567734`,0.0583973`,0.0602409`,0.0623353`,0.0647164`,0.0674131`,0.070404`,0.0736489`,0.0770978`,0.0806894`,0.0843613`,0.0880904`,0.091863`,0.0956637`,0.0994755`,0.103286`,0.107103`,0.110947`,0.114838`,0.118802`,0.122863`,0.127026`,0.131293`,0.135666`,0.140145`,0.144731`,0.149415`,0.154189`,0.159038`,0.163952`,0.168932`,0.174063`,0.179457`,0.185241`,0.191556`,0.198532`,0.206182`,0.214485`,0.223411`,0.232926`,0.242992`,0.253616`,0.26481`,0.276587`,0.288959`,0.301934`,0.315508`,0.329673`,0.344416`,0.359716`,0.37555`,0.391895`,0.408722`,0.425998`,0.443683`,0.461731`,0.480094`,0.498717`,0.517539`,0.536494`,0.555493`,0.574386`,0.592995`,0.611124`,0.628561`,0.645139`,0.660907`,0.675993`,0.690542`,0.70472`,0.718662`,0.732323`,0.745606`,0.75841`,0.77063`,0.782208`,0.79329`,0.804084`,0.814813`,0.825711`,0.836943`,0.848349`,0.859676`,0.870656`,0.881011`,0.890496`,0.899052`,0.906669`,0.913341`,0.919067`,0.923898`,0.928099`,0.931995`,0.935916`,0.940198`,0.945076`,0.950367`,0.955775`,0.961`,0.965733`,0.969744`,0.973133`,0.976086`,0.978793`,0.981445`,0.984186`,0.986965`,0.989678`,0.99222`,0.994486`,0.996386`,0.997895`,0.999004`,0.999706`,0.999993`,0.999837`,0.999123`,0.997719`,0.995491`,0.99231`,0.988146`,0.983345`,0.978342`,0.973564`,0.969429`,0.966211`,0.96363`,0.961273`,0.958732`,0.955602`,0.951569`,0.946654`,0.940962`,0.9346`,0.927673`,0.920264`,0.912391`,0.90405`,0.895243`,0.885969`,0.876242`,0.866117`,0.855658`,0.844926`,0.833982`,0.822859`,0.811491`,0.799794`,0.787689`,0.775103`,0.761996`,0.748425`,0.73447`,0.720208`,0.705713`,0.691044`,0.676212`,0.66122`,0.646072`,0.630773`,0.615349`,0.599888`,0.584489`,0.56924`,0.554224`,0.539469`,0.524827`,0.510124`,0.495206`,0.479941`,0.46427`,0.448338`,0.432329`,0.416406`,0.400711`,0.385355`,0.370377`,0.355793`,0.341618`,0.327864`,0.314541`,0.301662`,0.289239`,0.277278`,0.265784`,0.25474`,0.244054`,0.233634`,0.223399`,0.213284`,0.203257`,0.19337`,0.183688`,0.174263`,0.165141`,0.156354`,0.147916`,0.139834`,0.132111`,0.124749`,0.117744`,0.111081`,0.104747`,0.0987277`,0.0930085`,0.0875769`,0.0824219`,0.0775328`,0.0728989`,0.06851`,0.0643554`,0.0604242`,0.0567057`,0.0531896`,0.0498661`,0.0467258`,0.0437598`,0.0409594`,0.0383165`,0.0358233`,0.0334725`,0.0312583`,0.0291751`,0.0272173`,0.025379`,0.0236541`,0.0220336`,0.0205092`,0.0190735`,0.0177201`,0.0164451`,0.015251`,0.0141404`,0.0131137`,0.0121701`,0.0113063`,0.0105131`,0.00978127`,0.009103`,0.0084717`,0.00788227`,0.00733213`,0.00681928`,0.00634173`,0.00589749`,0.00548444`,0.00509978`,0.00474086`,0.00440538`,0.00409129`,0.00379703`,0.00352187`,0.0032652`,0.00302632`,0.00280447`,0.00259882`,0.00240849`,0.00223259`,0.00207024`,0.00192058`,0.00178269`,0.0016554`,0.00153762`,0.00142839`,0.00132687`,0.00123238`,0.00114456`,0.00106308`,0.000987592`,0.000917777`,0.000853264`,0.000793589`,0.000738306`,0.000687018`,0.000639373`,0.000595057`,0.000553797`,0.00051535`,0.000479496`,0.000446035`,0.000414809`,0.000385749`,0.000358792`,0.000333861`,0.000310869`,0.000289699`,0.000270145`,0.000252007`,0.000235117`,0.000219329`,0.000204535`,0.000190692`,0.000177771`,0.000165736`,0.000154549`,0.000144167`,0.000134528`,0.000125574`,0.000117251`,0.000109508`,0.0001023`,0.0000955828`,0.0000893161`,0.0000834631`,0.0000779912`,0.000072873`,0.0000680921`,0.0000636342`,0.0000594841`,0.0000556264`,0.000052043`,0.0000487063`,0.00004559`,0.000042671`,0.0000399295`,0.0000373509`,0.0000349326`,0.000032673`,0.000030569`,0.0000286163`,0.0000268077`,0.0000251286`,0.0000235645`,0.0000221026`,0.0000207321`,0.0000194444`,0.0000182351`,0.0000171008`,0.000016038`,0.0000150432`,0.0000141127`,0.000013242`,0.0000124263`,0.0000116618`,0.0000109446`,0.0000102716`,9.64036`*^-6,9.04897`*^-6,8.49535`*^-6,7.9775`*^-6,7.49341`*^-6,7.04079`*^-6,6.61744`*^-6,6.22133`*^-6,5.85057`*^-6,5.50333`*^-6,5.17756`*^-6,4.87135`*^-6,4.583`*^-6,4.31102`*^-6,4.05422`*^-6,3.81213`*^-6,3.58438`*^-6,3.37053`*^-6,3.17009`*^-6,2.98248`*^-6,2.80691`*^-6,2.64257`*^-6,2.48873`*^-6,2.34468`*^-6,2.20974`*^-6,2.08315`*^-6,1.96419`*^-6,1.85222`*^-6,1.74666`*^-6,1.64705`*^-6,1.55307`*^-6,1.46448`*^-6,1.381`*^-6,1.30241`*^-6,1.22844`*^-6,1.15888`*^-6,1.09348`*^-6,1.03203`*^-6,9.74306`*^-7},{0.000368349`,0.000448015`,0.000543965`,0.000658983`,0.000796121`,0.000958658`,0.00115002`,0.00137367`,0.00163296`,0.00193089`,0.00226991`,0.0026521`,0.0030811`,0.00356156`,0.004099`,0.0047001`,0.00537186`,0.00611757`,0.00693795`,0.00783144`,0.00879369`,0.00981865`,0.0109044`,0.0120509`,0.0132582`,0.0145277`,0.01586`,0.0172496`,0.0186878`,0.0201638`,0.0216649`,0.0231801`,0.0247139`,0.0262785`,0.0278905`,0.0295714`,0.0313438`,0.0332151`,0.0351889`,0.0372683`,0.0394566`,0.0417546`,0.0441544`,0.0466432`,0.049205`,0.0518199`,0.0544645`,0.0571131`,0.0597369`,0.0623038`,0.0647782`,0.0671329`,0.0693844`,0.0715658`,0.0737164`,0.0758812`,0.078098`,0.0803538`,0.0826198`,0.0848644`,0.0870524`,0.089164`,0.0912523`,0.093395`,0.0956775`,0.0981934`,0.101031`,0.104229`,0.107814`,0.111817`,0.116272`,0.121204`,0.126573`,0.132311`,0.138334`,0.144541`,0.150828`,0.157146`,0.163457`,0.169721`,0.175893`,0.181938`,0.187872`,0.193731`,0.199557`,0.205398`,0.211302`,0.217283`,0.223347`,0.229501`,0.235754`,0.242108`,0.248545`,0.255037`,0.261554`,0.268063`,0.274561`,0.28118`,0.288097`,0.295508`,0.30363`,0.312649`,0.322565`,0.333319`,0.344844`,0.357061`,0.369895`,0.383355`,0.397467`,0.41226`,0.427764`,0.444001`,0.460947`,0.478562`,0.496795`,0.515587`,0.534868`,0.554575`,0.57464`,0.594984`,0.61552`,0.636162`,0.656872`,0.677624`,0.698393`,0.719154`,0.739844`,0.760235`,0.780039`,0.798941`,0.81661`,0.832783`,0.84755`,0.861113`,0.873698`,0.88555`,0.896873`,0.907638`,0.917757`,0.927137`,0.935687`,0.943362`,0.950309`,0.956733`,0.962844`,0.968858`,0.974919`,0.98085`,0.986388`,0.991267`,0.995217`,0.998007`,0.999595`,0.999982`,0.999177`,0.997193`,0.994102`,0.990204`,0.985855`,0.981404`,0.977193`,0.973441`,0.969881`,0.966133`,0.961823`,0.956583`,0.950167`,0.942773`,0.934709`,0.926271`,0.91775`,0.909339`,0.900895`,0.892197`,0.883035`,0.873205`,0.862565`,0.851173`,0.839132`,0.826545`,0.813509`,0.800082`,0.786166`,0.771635`,0.756376`,0.740291`,0.723369`,0.70589`,0.688184`,0.670554`,0.653274`,0.636524`,0.620217`,0.604211`,0.588375`,0.572597`,0.556783`,0.540896`,0.524912`,0.508817`,0.492599`,0.476268`,0.459893`,0.443551`,0.427314`,0.411246`,0.395396`,0.379782`,0.36441`,0.349289`,0.334429`,0.319843`,0.305564`,0.291625`,0.278053`,0.264872`,0.252099`,0.239747`,0.227822`,0.21633`,0.205273`,0.19465`,0.184448`,0.174654`,0.165256`,0.156243`,0.147602`,0.139329`,0.131416`,0.123856`,0.116641`,0.109766`,0.103226`,0.0970205`,0.091143`,0.0855872`,0.0803428`,0.0753913`,0.0707136`,0.0662924`,0.062112`,0.0581595`,0.0544276`,0.0509098`,0.0475991`,0.0444879`,0.0415659`,0.0388152`,0.0362181`,0.0337599`,0.0314282`,0.0292176`,0.0271403`,0.0252084`,0.0234286`,0.0218037`,0.0203285`,0.0189779`,0.0177272`,0.016556`,0.015448`,0.0143924`,0.0133896`,0.0124414`,0.0115488`,0.010712`,0.00992994`,0.00920057`,0.00852126`,0.00788945`,0.00730255`,0.0067582`,0.00625474`,0.00579045`,0.00536347`,0.00497179`,0.004613`,0.00428339`,0.0039794`,0.00369803`,0.00343667`,0.00319326`,0.00296653`,0.00275543`,0.00255896`,0.00237617`,0.00220618`,0.00204809`,0.0019011`,0.00176442`,0.00163734`,0.00151916`,0.00140913`,0.00130655`,0.00121078`,0.00112128`,0.00103766`,0.000959892`,0.000887951`,0.000821729`,0.000761051`,0.000705623`,0.000654874`,0.00060824`,0.00056524`,0.000525457`,0.00048855`,0.000454277`,0.000422436`,0.000392839`,0.000365317`,0.00033971`,0.000315856`,0.000293607`,0.000272834`,0.000253417`,0.000235265`,0.000218331`,0.000202574`,0.000187948`,0.000174402`,0.000161878`,0.000150305`,0.000139612`,0.000129734`,0.000120608`,0.000112176`,0.000104373`,0.0000971383`,0.0000904202`,0.0000841716`,0.0000783538`,0.0000729425`,0.0000679164`,0.0000632542`,0.0000589349`,0.000054936`,0.0000512291`,0.0000477872`,0.0000445862`,0.0000416049`,0.0000388245`,0.0000362302`,0.0000338086`,0.0000315474`,0.0000294354`,0.0000274634`,0.0000256268`,0.0000239217`,0.0000223432`,0.000020886`,0.0000195424`,0.000018299`,0.0000171423`,0.0000160611`,0.0000150458`,0.0000140893`,0.0000131899`,0.0000123462`,0.0000115569`,0.00001082`,0.0000101334`,9.49367`*^-6,8.89736`*^-6,8.34135`*^-6,7.82271`*^-6,7.33865`*^-6,6.88612`*^-6,6.46228`*^-6,6.06462`*^-6,5.69093`*^-6,5.33942`*^-6,5.00929`*^-6,4.69984`*^-6,4.41034`*^-6,4.13998`*^-6,3.88772`*^-6,3.65186`*^-6,3.4307`*^-6,3.22278`*^-6,3.02683`*^-6,2.84192`*^-6,2.66795`*^-6,2.50491`*^-6,2.35267`*^-6,2.211`*^-6,2.07946`*^-6,1.957`*^-6,1.84258`*^-6,1.73528`*^-6,1.63433`*^-6,1.5391`*^-6,1.44932`*^-6,1.36478`*^-6,1.28526`*^-6,1.21054`*^-6,1.14038`*^-6,1.07446`*^-6,1.01247`*^-6,9.5413`*^-7,8.9917`*^-7,8.47379`*^-7,7.98635`*^-7,7.52832`*^-7,7.09857`*^-7,6.69594`*^-7,6.31907`*^-7,5.96604`*^-7,5.63495`*^-7,5.32408`*^-7,5.03187`*^-7,4.75686`*^-7,4.49753`*^-7,4.25249`*^-7,4.0205`*^-7,3.80046`*^-7,3.59156`*^-7,3.39356`*^-7,3.20633`*^-7,3.02966`*^-7,2.86329`*^-7,2.70687`*^-7,2.5598`*^-7,2.42147`*^-7,2.2913`*^-7,2.16878`*^-7,2.05338`*^-7,1.94449`*^-7,1.84155`*^-7,1.74407`*^-7,1.65158`*^-7,1.56373`*^-7,1.48031`*^-7,1.40117`*^-7,1.32615`*^-7,1.25508`*^-7,1.18781`*^-7,1.12416`*^-7,1.06398`*^-7,1.00711`*^-7,9.53411`*^-8},{0.00954729`,0.0114794`,0.0137986`,0.0165746`,0.0198869`,0.023825`,0.0284877`,0.0339832`,0.0404274`,0.0479417`,0.0566498`,0.0666757`,0.0781479`,0.0911925`,0.105926`,0.122451`,0.140844`,0.16114`,0.183325`,0.207327`,0.233008`,0.260183`,0.288723`,0.318512`,0.349431`,0.381363`,0.414141`,0.44735`,0.480439`,0.512767`,0.543618`,0.572399`,0.599284`,0.624786`,0.649576`,0.674474`,0.700186`,0.72646`,0.752726`,0.778333`,0.802555`,0.824818`,0.845422`,0.864961`,0.8841`,0.903573`,0.923844`,0.944055`,0.96292`,0.979057`,0.99102`,0.997765`,0.999982`,0.998861`,0.995628`,0.991515`,0.987377`,0.982619`,0.976301`,0.967513`,0.955393`,0.939499`,0.920807`,0.900592`,0.88004`,0.86024`,0.842031`,0.825572`,0.81086`,0.797902`,0.786704`,0.777119`,0.768365`,0.759538`,0.749777`,0.738268`,0.724389`,0.708113`,0.689572`,0.668927`,0.646359`,0.622112`,0.596591`,0.570216`,0.543373`,0.516411`,0.489647`,0.463406`,0.437965`,0.413549`,0.390333`,0.368394`,0.347582`,0.327724`,0.308676`,0.290322`,0.272626`,0.255772`,0.239945`,0.22528`,0.211867`,0.199719`,0.188674`,0.178557`,0.169217`,0.160526`,0.152368`,0.14462`,0.137173`,0.129937`,0.122839`,0.115834`,0.108922`,0.102118`,0.0954374`,0.0888965`,0.0825343`,0.0764613`,0.0707769`,0.0655491`,0.060821`,0.0565919`,0.0527659`,0.049244`,0.045947`,0.0428123`,0.0398014`,0.0369227`,0.0341909`,0.0316158`,0.0292033`,0.0269536`,0.0248575`,0.0229047`,0.0210855`,0.0193912`,0.0178145`,0.0163514`,0.014998`,0.0137497`,0.0126013`,0.0115466`,0.0105766`,0.00968268`,0.00885746`,0.00809453`,0.0073889`,0.00673799`,0.00613947`,0.00559073`,0.005089`,0.0046312`,0.00421366`,0.00383286`,0.00348559`,0.00316893`,0.00288021`,0.00261698`,0.00237701`,0.00215829`,0.00195896`,0.00177737`,0.00161218`,0.00146215`,0.00132606`,0.00120277`,0.00109118`,0.000990135`,0.000898564`,0.000815524`,0.000740174`,0.000671772`,0.000609693`,0.000553372`,0.000502292`,0.000455979`,0.000413997`,0.00037594`,0.000341439`,0.00031016`,0.0002818`,0.000256084`,0.000232764`,0.000211616`,0.000192436`,0.000175039`,0.000159257`,0.00014494`,0.000131948`,0.000120157`,0.000109454`,0.0000997367`,0.0000909125`,0.0000828976`,0.000075616`,0.0000689991`,0.0000629846`,0.0000575163`,0.0000525432`,0.0000480192`,0.0000439024`,0.0000401551`,0.0000367431`,0.0000336353`,0.0000308037`,0.0000282228`,0.0000258697`,0.0000237235`,0.0000217653`,0.0000199779`,0.0000183459`,0.0000168551`,0.0000154929`,0.0000142476`,0.0000131087`,0.0000120667`,0.0000111131`,0.0000102399`,9.43999`*^-6,8.70695`*^-6,8.03488`*^-6,7.41844`*^-6,6.85279`*^-6,6.33352`*^-6,5.85662`*^-6,5.41843`*^-6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

rgbTable=
{{390,395,400,405,410,415,420,425,430,435,440,445,450,455,460,465,470,475,480,485,490,495,500,505,510,515,520,525,530,535,540,545,550,555,560,565,570,575,580,585,590,595,600,605,610,615,620,625,630,635,640,645,650,655,660,665,670,675,680,685,690,695,700,705,710,715,720,725,730},{0.0018397`,0.0046153`,0.0096264`,0.018979`,0.030803`,0.042459`,0.051662`,0.052837`,0.044287`,0.03222`,0.014763`,-0.0023392`,-0.02913`,-0.060677`,-0.096224`,-0.13759`,-0.17486`,-0.2126`,-0.2378`,-0.25674`,-0.27727`,-0.29125`,-0.295`,-0.29706`,-0.26759`,-0.21725`,-0.14768`,-0.035184`,0.10614`,0.25981`,0.41976`,0.59259`,0.79004`,1.0078`,1.2283`,1.4727`,1.7476`,2.0214`,2.2724`,2.4896`,2.6725`,2.8093`,2.8717`,2.8525`,2.7601`,2.5989`,2.3743`,2.1054`,1.8145`,1.5247`,1.2543`,1.0076`,0.78642`,0.59659`,0.4432`,0.3241`,0.23455`,0.16884`,0.12086`,0.085811`,0.06026`,0.04148`,0.028114`,0.019117`,0.013305`,0.0094092`,0.0065177`,0.0045377`,0.0031742`},{-0.00045393`,-0.0010464`,-0.0021689`,-0.0044304`,-0.0072048`,-0.012579`,-0.016651`,-0.02124`,-0.019936`,-0.016097`,-0.0073457`,0.001369`,0.01961`,0.043464`,0.070954`,0.11022`,0.15088`,0.19794`,0.24042`,0.27993`,0.33353`,0.40521`,0.4906`,0.59673`,0.70184`,0.80852`,0.91076`,0.98482`,1.0339`,1.0538`,1.0512`,1.0498`,1.0368`,0.99826`,0.93783`,0.88039`,0.82835`,0.74686`,0.6493`,0.56317`,0.47675`,0.38484`,0.30069`,0.22853`,0.16575`,0.11373`,0.074682`,0.046504`,0.026333`,0.012724`,0.0045033`,0.000096611`,-0.0019645`,-0.0026327`,-0.0026262`,-0.0023027`,-0.00187`,-0.0014424`,-0.0010755`,-0.00079004`,-0.00056765`,-0.00039274`,-0.00026231`,-0.00017512`,-0.0001214`,-0.00008576`,-0.000057677`,-0.000039003`,-0.000026511`},{0.012152`,0.03111`,0.062371`,0.13161`,0.2275`,0.35897`,0.52396`,0.68586`,0.79604`,0.89459`,0.96395`,0.99814`,0.91875`,0.82487`,0.78554`,0.66723`,0.61098`,0.48829`,0.36195`,0.26634`,0.19593`,0.1473`,0.10749`,0.076714`,0.050248`,0.028781`,0.013309`,0.002117`,-0.0041574`,-0.0083032`,-0.012191`,-0.014039`,-0.014681`,-0.014947`,-0.014613`,-0.013782`,-0.01265`,-0.011356`,-0.0099317`,-0.0084148`,-0.007021`,-0.0057437`,-0.0042743`,-0.0029132`,-0.0022693`,-0.0019966`,-0.0015069`,-0.00093822`,-0.00055316`,-0.00031668`,-0.00014319`,-4.0831`*^-6,0.00011081`,0.00019175`,0.00022656`,0.0002152`,0.00016361`,0.000097164`,0.000051033`,0.000035271`,0.000031211`,0.000024508`,0.000016521`,0.000011124`,8.6965`*^-6,7.4351`*^-6,6.1057`*^-6,5.0277`*^-6,4.1251`*^-6}};

xyzTable=
{{390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830},{0.003769647`,0.004532416`,0.005446553`,0.006538868`,0.007839699`,0.009382967`,0.01120608`,0.01334965`,0.0158569`,0.01877286`,0.02214302`,0.02601285`,0.03043036`,0.03544325`,0.0410964`,0.04742986`,0.05447394`,0.06223612`,0.07070048`,0.07982513`,0.08953803`,0.09974848`,0.1104019`,0.1214566`,0.1328741`,0.1446214`,0.1566468`,0.1687901`,0.1808328`,0.1925216`,0.2035729`,0.2137531`,0.2231348`,0.2319245`,0.2403892`,0.2488523`,0.2575896`,0.2664991`,0.2753532`,0.2838921`,0.2918246`,0.29892`,0.3052993`,0.3112031`,0.3169047`,0.3227087`,0.3288194`,0.3349242`,0.3405452`,0.3451688`,0.3482554`,0.3494153`,0.3489075`,0.3471746`,0.3446705`,0.3418483`,0.339024`,0.3359926`,0.3324276`,0.3280157`,0.3224637`,0.3156225`,0.3078201`,0.2994771`,0.2909776`,0.2826646`,0.2747962`,0.2674312`,0.2605847`,0.2542749`,0.2485254`,0.2433039`,0.2383414`,0.2333253`,0.2279619`,0.2219781`,0.2151735`,0.2075619`,0.1992183`,0.190229`,0.1806905`,0.1707154`,0.1604471`,0.1500244`,0.1395705`,0.129192`,0.1189859`,0.1090615`,0.09951424`,0.0904185`,0.08182895`,0.07376817`,0.06619477`,0.0590638`,0.05234242`,0.04600865`,0.04006154`,0.03454373`,0.02949091`,0.0249214`,0.02083981`,0.01723591`,0.01407924`,0.01134516`,0.009019658`,0.007097731`,0.005571145`,0.004394566`,0.003516303`,0.002887638`,0.002461588`,0.002206348`,0.002149559`,0.002337091`,0.002818931`,0.003649178`,0.004891359`,0.006629364`,0.008942902`,0.01190224`,0.01556989`,0.01997668`,0.02504698`,0.0306753`,0.03674999`,0.04315171`,0.04978584`,0.05668554`,0.06391651`,0.07154352`,0.07962917`,0.08821473`,0.09726978`,0.1067504`,0.1166192`,0.1268468`,0.137406`,0.1482471`,0.1593076`,0.1705181`,0.1818026`,0.193109`,0.2045085`,0.2161166`,0.228065`,0.2405015`,0.2535441`,0.26713`,0.2811351`,0.2954164`,0.3098117`,0.3241678`,0.3384319`,0.3525786`,0.3665839`,0.3804244`,0.3940988`,0.4076972`,0.4213484`,0.4352003`,0.4494206`,0.4641616`,0.4794395`,0.495218`,0.5114395`,0.5280233`,0.5448696`,0.5618898`,0.5790137`,0.5961882`,0.6133784`,0.6305897`,0.6479223`,0.6654866`,0.6833782`,0.7016774`,0.720411`,0.7394495`,0.7586285`,0.7777885`,0.796775`,0.815453`,0.8337389`,0.8515493`,0.8687862`,0.8853376`,0.9011588`,0.9165278`,0.9318245`,0.9474524`,0.9638388`,0.9812596`,0.9992953`,1.017343`,1.03479`,1.051011`,1.065522`,1.078421`,1.089944`,1.10032`,1.109767`,1.118438`,1.126266`,1.133138`,1.138952`,1.14362`,1.147095`,1.149464`,1.150838`,1.151326`,1.151033`,1.150002`,1.148061`,1.144998`,1.140622`,1.134757`,1.127298`,1.118342`,1.108033`,1.096515`,1.083928`,1.070387`,1.055934`,1.040592`,1.024385`,1.007344`,0.9895268`,0.9711213`,0.9523257`,0.9333248`,0.9142877`,0.8952798`,0.8760157`,0.8561607`,0.8354235`,0.8135565`,0.7904565`,0.7664364`,0.7418777`,0.7171219`,0.6924717`,0.66816`,0.6442697`,0.620845`,0.5979243`,0.575541`,0.5537296`,0.5325412`,0.5120218`,0.492207`,0.4731224`,0.4547417`,0.4368719`,0.4193121`,0.401898`,0.3844986`,0.3670592`,0.3497167`,0.3326305`,0.3159341`,0.2997374`,0.2841189`,0.2691053`,0.2547077`,0.2409319`,0.2277792`,0.2152431`,0.203301`,0.1919276`,0.1810987`,0.1707914`,0.1609842`,0.1516577`,0.1427936`,0.1343737`,0.1263808`,0.1187979`,0.1116088`,0.1047975`,0.09834835`,0.09224597`,0.08647506`,0.08101986`,0.07586514`,0.07099633`,0.0663996`,0.06206225`,0.05797409`,0.05412533`,0.050506`,0.04710606`,0.04391411`,0.04091411`,0.03809067`,0.03543034`,0.03292138`,0.03055672`,0.02834146`,0.02628033`,0.02437465`,0.02262306`,0.02101935`,0.01954647`,0.01818727`,0.01692727`,0.01575417`,0.01465854`,0.01363571`,0.01268205`,0.01179394`,0.01096778`,0.01019964`,0.009484317`,0.008816851`,0.008192921`,0.00760875`,0.007061391`,0.006549509`,0.00607197`,0.005627476`,0.005214608`,0.004831848`,0.004477579`,0.004150166`,0.003847988`,0.003569452`,0.003312857`,0.003076022`,0.002856894`,0.002653681`,0.002464821`,0.00228906`,0.002125694`,0.001974121`,0.001833723`,0.001703876`,0.001583904`,0.001472939`,0.001370151`,0.001274803`,0.001186238`,0.001103871`,0.001027194`,0.0009557493`,0.0008891262`,0.0008269535`,0.0007689351`,0.0007149425`,0.000664859`,0.0006185421`,0.0005758303`,0.0005365046`,0.0005001842`,0.0004665005`,0.0004351386`,0.0004058303`,0.0003783733`,0.0003526892`,0.0003287199`,0.0003063998`,0.0002856577`,0.0002664108`,0.0002485462`,0.0002319529`,0.00021653`,0.0002021853`,0.0001888338`,0.0001763935`,0.0001647895`,0.0001539542`,0.000143827`,0.0001343572`,0.0001255141`,0.0001172706`,0.0001095983`,0.0001024685`,0.00009584715`,0.00008968316`,0.00008392734`,0.00007853708`,0.00007347551`,0.00006871576`,0.00006425257`,0.00006008292`,0.00005620098`,0.0000525987`,0.00004926279`,0.00004616623`,0.00004328212`,0.00004058715`,0.00003806114`,0.00003568818`,0.00003346023`,0.0000313709`,0.00002941371`,0.00002758222`,0.00002586951`,0.00002426701`,0.00002276639`,0.00002136009`,0.00002004122`,0.0000188038`,0.00001764358`,0.00001655671`,0.00001553939`,0.00001458792`,0.00001369853`,0.00001286705`,0.00001208947`,0.00001136207`,0.00001068141`,0.00001004411`,9.446399`*^-6,8.884754`*^-6,8.35605`*^-6,7.857521`*^-6,7.386996`*^-6,6.943576`*^-6,6.526548`*^-6,6.135087`*^-6,5.768284`*^-6,5.425069`*^-6,5.103974`*^-6,4.803525`*^-6,4.52235`*^-6,4.259166`*^-6,4.012715`*^-6,3.781597`*^-6,3.564496`*^-6,3.360236`*^-6,3.167765`*^-6,2.986206`*^-6,2.814999`*^-6,2.653663`*^-6,2.501725`*^-6,2.358723`*^-6,2.224206`*^-6,2.097737`*^-6,1.978894`*^-6,1.867268`*^-6,1.762465`*^-6},{0.0004146161`,0.0005028333`,0.0006084991`,0.0007344436`,0.0008837389`,0.001059646`,0.001265532`,0.001504753`,0.001780493`,0.002095572`,0.002452194`,0.002852216`,0.003299115`,0.003797466`,0.004352768`,0.004971717`,0.005661014`,0.006421615`,0.007250312`,0.008140173`,0.00907986`,0.01005608`,0.01106456`,0.01210522`,0.01318014`,0.01429377`,0.01545004`,0.01664093`,0.01785302`,0.01907018`,0.02027369`,0.02144805`,0.02260041`,0.02374789`,0.02491247`,0.02612106`,0.02739923`,0.02874993`,0.03016909`,0.03165145`,0.03319038`,0.03477912`,0.03641495`,0.03809569`,0.03981843`,0.0415794`,0.04337098`,0.0451718`,0.0469542`,0.04868718`,0.05033657`,0.05187611`,0.05332218`,0.05470603`,0.05606335`,0.05743393`,0.05885107`,0.06030809`,0.06178644`,0.0632657`,0.06472352`,0.06614749`,0.06757256`,0.06904928`,0.0706328`,0.07238339`,0.0743596`,0.07659383`,0.07911436`,0.08195345`,0.08514816`,0.08872657`,0.09266008`,0.09689723`,0.1013746`,0.1060145`,0.1107377`,0.1155111`,0.1203122`,0.1251161`,0.1298957`,0.1346299`,0.1393309`,0.1440235`,0.1487372`,0.1535066`,0.1583644`,0.1633199`,0.1683761`,0.1735365`,0.1788048`,0.1841819`,0.1896559`,0.1952101`,0.2008259`,0.2064828`,0.2121826`,0.2180279`,0.2241586`,0.2307302`,0.237916`,0.2458706`,0.2546023`,0.264076`,0.274249`,0.285068`,0.2964837`,0.308501`,0.3211393`,0.3344175`,0.3483536`,0.3629601`,0.3782275`,0.3941359`,0.4106582`,0.4277595`,0.4453993`,0.4635396`,0.4821376`,0.501143`,0.5204972`,0.5401387`,0.5600208`,0.5800972`,0.6003172`,0.6206256`,0.6409398`,0.6610772`,0.6808134`,0.6999044`,0.718089`,0.7351593`,0.7511821`,0.7663143`,0.7807352`,0.7946448`,0.8082074`,0.8213817`,0.8340701`,0.8461711`,0.8575799`,0.8682408`,0.8783061`,0.8879907`,0.8975211`,0.9071347`,0.9169947`,0.9269295`,0.9366731`,0.9459482`,0.9544675`,0.9619834`,0.968439`,0.9738289`,0.9781519`,0.9814106`,0.9836669`,0.9852081`,0.9863813`,0.9875357`,0.9890228`,0.9910811`,0.9934913`,0.9959172`,0.9980205`,0.9994608`,0.999993`,0.9997557`,0.9989839`,0.9979123`,0.9967737`,0.9957356`,0.9947115`,0.9935534`,0.9921156`,0.9902549`,0.9878596`,0.9849324`,0.9815036`,0.9776035`,0.9732611`,0.9684764`,0.9631369`,0.9571062`,0.950254`,0.9424569`,0.9336897`,0.9242893`,0.9146707`,0.9052333`,0.8963613`,0.8883069`,0.8808462`,0.8736445`,0.8663755`,0.8587203`,0.8504295`,0.8415047`,0.8320109`,0.8220154`,0.8115868`,0.8007874`,0.7896515`,0.7782053`,0.7664733`,0.7544785`,0.7422473`,0.7298229`,0.7172525`,0.7045818`,0.6918553`,0.6791009`,0.6662846`,0.6533595`,0.6402807`,0.6270066`,0.6135148`,0.5998494`,0.5860682`,0.5722261`,0.5583746`,0.5445535`,0.5307673`,0.517013`,0.5032889`,0.489595`,0.4759442`,0.4623958`,0.4490154`,0.4358622`,0.4229897`,0.4104152`,0.3980356`,0.38573`,0.3733907`,0.3609245`,0.348286`,0.3355702`,0.3228963`,0.3103704`,0.2980865`,0.286116`,0.2744822`,0.2631953`,0.2522628`,0.2416902`,0.2314809`,0.2216378`,0.2121622`,0.2030542`,0.1943124`,0.1859227`,0.1778274`,0.1699654`,0.1622841`,0.1547397`,0.1473081`,0.1400169`,0.1329013`,0.1259913`,0.119312`,0.112882`,0.1067113`,0.1008052`,0.09516653`,0.08979594`,0.08469044`,0.07984009`,0.07523372`,0.07086061`,0.06671045`,0.0627736`,0.05904179`,0.05550703`,0.05216139`,0.04899699`,0.04600578`,0.04317885`,0.04050755`,0.03798376`,0.03559982`,0.03334856`,0.03122332`,0.0292178`,0.02732601`,0.02554223`,0.02386121`,0.02227859`,0.0207902`,0.01939185`,0.01807939`,0.01684817`,0.01569188`,0.01460446`,0.01358062`,0.01261573`,0.01170696`,0.01085608`,0.01006476`,0.009333376`,0.008661284`,0.008046048`,0.00748113`,0.006959987`,0.00647707`,0.006027677`,0.005608169`,0.005216691`,0.004851785`,0.004512008`,0.004195941`,0.003902057`,0.003628371`,0.003373005`,0.003134315`,0.002910864`,0.002701528`,0.002505796`,0.002323231`,0.002153333`,0.001995557`,0.001849316`,0.001713976`,0.001588899`,0.001473453`,0.001367022`,0.001268954`,0.001178421`,0.001094644`,0.001016943`,0.0009447269`,0.0008775171`,0.0008150438`,0.0007570755`,0.0007033755`,0.000653705`,0.0006078048`,0.0005653435`,0.0005260046`,0.0004895061`,0.000455597`,0.0004240548`,0.000394686`,0.0003673178`,0.0003417941`,0.0003179738`,0.0002957441`,0.0002750558`,0.000255864`,0.0002381142`,0.0002217445`,0.0002066711`,0.0001927474`,0.0001798315`,0.0001678023`,0.0001565566`,0.0001460168`,0.0001361535`,0.0001269451`,0.0001183671`,0.0001103928`,0.0001029908`,0.00009611836`,0.00008973323`,0.00008379694`,0.00007827442`,0.00007313312`,0.00006834142`,0.00006387035`,0.00005969389`,0.00005578862`,0.00005213509`,0.00004872179`,0.00004553845`,0.00004257443`,0.00003981884`,0.00003725877`,0.00003487467`,0.00003264765`,0.0000305614`,0.00002860175`,0.00002675841`,0.00002502943`,0.00002341373`,0.00002190914`,0.00002051259`,0.00001921902`,0.00001801796`,0.00001689899`,0.00001585309`,0.00001487243`,0.00001395085`,0.00001308528`,0.00001227327`,0.00001151233`,0.00001080001`,0.00001013364`,9.509919`*^-6,8.92563`*^-6,8.377852`*^-6,7.86392`*^-6,7.381539`*^-6,6.929096`*^-6,6.505136`*^-6,6.108221`*^-6,5.736935`*^-6,5.389831`*^-6,5.065269`*^-6,4.761667`*^-6,4.477561`*^-6,4.211597`*^-6,3.962457`*^-6,3.728674`*^-6,3.508881`*^-6,3.301868`*^-6,3.106561`*^-6,2.922119`*^-6,2.748208`*^-6,2.58456`*^-6,2.430867`*^-6,2.286786`*^-6,2.151905`*^-6,2.025656`*^-6,1.907464`*^-6,1.796794`*^-6,1.693147`*^-6,1.596032`*^-6,1.504903`*^-6,1.419245`*^-6,1.3386`*^-6,1.262556`*^-6,1.190771`*^-6,1.123031`*^-6,1.059151`*^-6,9.989507`*^-7,9.422514`*^-7,8.888804`*^-7,8.38669`*^-7,7.914539`*^-7,7.47077`*^-7,7.05386`*^-7},{0.0184726`,0.02221101`,0.02669819`,0.03206937`,0.03847832`,0.04609784`,0.05511953`,0.06575257`,0.07822113`,0.09276013`,0.109609`,0.1290077`,0.1512047`,0.1764441`,0.2049517`,0.2369246`,0.2725123`,0.311782`,0.3547064`,0.4011473`,0.4508369`,0.5034164`,0.5586361`,0.6162734`,0.6760982`,0.7378822`,0.8013019`,0.8655573`,0.9295791`,0.9921293`,1.051821`,1.107509`,1.159527`,1.208869`,1.256834`,1.305008`,1.354758`,1.405594`,1.456414`,1.50596`,1.552826`,1.595902`,1.635768`,1.673573`,1.710604`,1.74828`,1.787504`,1.826609`,1.863108`,1.894332`,1.917479`,1.930529`,1.934819`,1.93265`,1.926395`,1.918437`,1.91043`,1.901224`,1.889`,1.871996`,1.848545`,1.817792`,1.781627`,1.742514`,1.702749`,1.664439`,1.629207`,1.59736`,1.568896`,1.543823`,1.522157`,1.503611`,1.486673`,1.469595`,1.450709`,1.42844`,1.401587`,1.370094`,1.33422`,1.294275`,1.25061`,1.203696`,1.154316`,1.103284`,1.051347`,0.9991789`,0.9473958`,0.8966222`,0.8473981`,0.8001576`,0.7552379`,0.7127879`,0.6725198`,0.6340976`,0.5972433`,0.5617313`,0.5274921`,0.4948809`,0.4642586`,0.4358841`,0.4099313`,0.3864261`,0.3650566`,0.3454812`,0.3274095`,0.3105939`,0.2948102`,0.2798194`,0.26541`,0.2514084`,0.2376753`,0.2241211`,0.2107484`,0.1975839`,0.1846574`,0.1720018`,0.1596918`,0.1479415`,0.1369428`,0.1268279`,0.1176796`,0.109497`,0.1020943`,0.09527993`,0.08890075`,0.08283548`,0.07700982`,0.07144001`,0.06615436`,0.06117199`,0.05650407`,0.05215121`,0.04809566`,0.0443172`,0.04079734`,0.03751912`,0.03446846`,0.03163764`,0.02901901`,0.02660364`,0.02438164`,0.02234097`,0.02046415`,0.01873456`,0.01713788`,0.01566174`,0.01429644`,0.01303702`,0.01187897`,0.01081725`,0.00984647`,0.008960687`,0.008152811`,0.007416025`,0.006744115`,0.006131421`,0.005572778`,0.005063463`,0.004599169`,0.004175971`,0.003790291`,0.003438952`,0.003119341`,0.002829038`,0.002565722`,0.002327186`,0.00211128`,0.001915766`,0.001738589`,0.00157792`,0.001432128`,0.001299781`,0.001179667`,0.001070694`,0.0009718623`,0.0008822531`,0.0008010231`,0.0007273884`,0.0006606347`,0.0006001146`,0.0005452416`,0.0004954847`,0.0004503642`,0.0004094455`,0.0003723345`,0.0003386739`,0.0003081396`,0.000280437`,0.0002552996`,0.0002324859`,0.0002117772`,0.0001929758`,0.0001759024`,0.0001603947`,0.0001463059`,0.0001335031`,0.000121866`,0.0001112857`,0.0001016634`,0.00009291003`,0.00008494468`,0.00007769425`,0.00007109247`,0.00006507936`,0.00005960061`,0.00005460706`,0.00005005417`,0.00004590157`,0.00004211268`,0.00003865437`,0.00003549661`,0.0000326122`,0.00002997643`,0.00002756693`,0.00002536339`,0.00002334738`,0.00002150221`,0.00001981268`,0.000018265`,0.00001684667`,0.00001554631`,0.0000143536`,0.00001325915`,0.00001225443`,0.00001133169`,0.00001048387`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`}};

{xbar,ybar,zbar} = {,,};

Color curves

$presets =
{
	"linear" -> {{0, 0}, {1, 1}},
	"flat" ->{{0,0.5`},{1,0.5`}},
	"negative" -> {{0,1},{1,0}},
	"high contrast" -> {{0,0},{0.2`,0.1`},{0.8`,0.9`},{1,1}},
	"low contrast" -> {{0,0},{0.2`,0.3`},{0.8`,0.7`},{1,1}},
	"burn" -> {{.25, 0}, {.75, 1}},
	"wash" -> {{0, .25}, {1, .75}}
};

validPointList = Alternatives[
	_?(MatrixQ[#, Internal`RealValuedNumericQ] && Last[Dimensions[#]] == 2&),
	Alternatives @@ Keys[$presets]
];

ClearAll[interpolationPlot]
interpolationPlot[fun_, style_, bgImages_, epilog_] := 
Framed[Plot[
	{x,
	fun[x]},
	{x, 0, 1},
	PlotRange   -> {0, 1},
	PlotRangePadding -> .001,
	Background -> White,
	AspectRatio -> 1,
	PlotStyle   -> {Directive[Black, Thin], style},
	GridLines   -> {Range[0,1,.25],Range[0,1,.25]},
	FrameTicks   -> None,
	Axes -> False,
	Frame -> False,
	Prolog -> (Inset[#, {0,0}, {0,0}, {1, 1}]& /@ Flatten[{bgImages}]),
	Epilog -> Dynamic[epilog],
	ImageSize -> 250
	],
FrameMargins -> 10, Background -> White]

ClearAll[interpolationPanel];
SetAttributes[interpolationPanel, HoldAll];
interpolationPanel[pts_, fun_, bg_ : {}, style_ : Black]:=
DynamicModule[{epilog = {}, prolog = {}, locators = pts},
Column[{
	EventHandler[LocatorPane[
		Dynamic[locators, (locators = DeleteDuplicates[#, Abs[First[#] - First[#2]] < .01 &])&],
		Dynamic[
			pts = If[Length[locators]>1, locators, locators = pts; locators];
			fun = generateCurve[pts];
			interpolationPlot[fun, style, bg, epilog]
			,
			TrackedSymbols :> {pts, locators}
		],
		{{0, 0}, {1, 1}},
		LocatorAutoCreate -> True
	],
	{"MouseDown" :> (epilog := selectioncross[Clip[MousePosition["Graphics",{0,0}],{0,1}]]), "MouseUp" :> (epilog = {})},
	PassEventsDown -> True
	],
	PopupMenu[Dynamic[locators],Reverse/@$presets, "custom"]
	},
	Alignment -> Center
]]

selectioncross[pt_] := {Dashed, Black, Thin, Line[{{{pt[[1]], 0}, {pt[[1]], 1}}, {{0, pt[[2]]}, {1, pt[[2]]}}}]}

histogramOptions = {AspectRatio -> 1, FrameTicks -> None, Frame -> False};
histogram[img_, "L"] := ImageHistogram[ColorSeparate[img,"L"], PlotStyle->{Gray, Opacity[.5]}, Sequence @@ histogramOptions]
histogram[img_, "R"] := ImageHistogram[ColorSeparate[img,"R"], PlotStyle->{Red, Opacity[.5]}, Sequence @@ histogramOptions]
histogram[img_, "G"] := ImageHistogram[ColorSeparate[img,"G"], PlotStyle->{Green, Opacity[.5]}, Sequence @@ histogramOptions]
histogram[img_, "B"] := ImageHistogram[ColorSeparate[img,"B"], PlotStyle->{Blue, Opacity[.5]}, Sequence @@ histogramOptions]

ClearAll[showClipping]
showClipping[img_Image] := ColorCombine[Binarize[#, # == 0 || # == 1 &]& /@ ColorSeparate[img, "RGB"], "RGB"]

ClearAll[generateCurve]
generateCurve[pts_] := 
With[
	{intFun = Quiet[Interpolation[pts, InterpolationOrder -> 3, Method -> "Spline"]]},
	Function[\[FormalX], 
		Evaluate[Piecewise[
			{
				{#2, \[FormalX] < #1}& @@ First@MinimalBy[pts, First],
				{#2, \[FormalX] > #1}& @@ First@MaximalBy[pts, First],
				{Clip[intFun[\[FormalX]], {0, 1}], True}
			}
		]]
	]
]
generateCurve[Automatic] := #&

ClearAll[applyCurves]
applyCurves[image_Image, {fRGB_, fR_, fG_, fB_}] := Module[{img = image},
	If[ImageColorSpace[image] =!= "RGB", ColorConvert[img, "RGB"]];
	img = ColorCombine[MapThread[ImageApply,{{fRGB@*fR,fRGB@*fG,fRGB@*fB}, ColorSeparate[RemoveAlphaChannel[img]]}]];
	If[Image`ImageInformation[image, "Transparency"], img = SetAlphaChannel[img, AlphaChannel[image]]];
	Image`CopyOptions[image, img, ColorSpace -> "FromTarget"]
]

ClearAll[curvePanel]
curvePanel[image_, points : validPointList | {Repeated[validPointList, {4}]} : Automatic] := 
DynamicModule[
	{img, background, extrapt, pts, ptsRGB, ptsR, ptsB, ptsG, fRGB, fR, fG, fB, data, clippingQ, compareQ, res},
	
	img = ImageResize[RemoveAlphaChannel[image], {300}];
	(*data = ImageData[img, "Byte", Interleaving -> False];*)
	
	Scan[Set[background[#], histogram[img, #]]&, {"L", "R", "G", "B"}];
	
	pts = Replace[points, {
			list : validPointList :> {list, Automatic, Automatic, Automatic},
			Automatic -> {Automatic, Automatic, Automatic, Automatic}
		}
	];
	pts = Replace[pts, Join[$presets, {Automatic -> {{0, 0}, {1, 1}}}], {1}];
	pts = Clip[pts, {0., 1.}];
	{ptsRGB, ptsR, ptsG, ptsB} = pts;
	extrapt = None;
	
	fRGB = fR = fG = fB = # &;
	clippingQ = compareQ = False;
	Deploy@Panel[Row[{
		TabView[{
			"RGB"   -> interpolationPanel[ptsRGB, fRGB, background["L"], Gray],
			"Red"   -> interpolationPanel[ptsR, fR, background["R"], Red],
			"Green" -> interpolationPanel[ptsG, fG, background["G"], Green],
			"Blue"  -> interpolationPanel[ptsB, fB, background["B"], Blue]
			}],
		Grid[{
			{
			 EventHandler[Button["View original", Dynamic[compareQ], ImageSize -> 150],
				{"MouseUp" :> (compareQ = False), 
				 "MouseDown" :> (compareQ = True)}],
			 EventHandler[Button["Show clipping", ImageSize -> 150],
				{"MouseDown" :> (clippingQ = True), 
				 "MouseUp" :> (clippingQ = False)}]
			 },
			{
			 Dynamic[
				Framed[Which[
					clippingQ,
					Image[showClipping[res], ImageSize-> All],
					compareQ,
					Image[img, ImageSize -> All],
					True,
					Image[res = applyCurves[img, {fRGB, fR, fG, fB}], ImageSize-> All]
				], ContentPadding -> False, Background -> White, FrameStyle -> None]
			],
			 SpanFromLeft
			 },
			{
			 Button["Print points", 
				Print[SortBy[First] /@ {ptsRGB, ptsR, ptsG, ptsB}],
				ImageSize -> 150],
			 Button["Print res", 
				Print[applyCurves[image, {fRGB, fR, fG, fB}]],
				ImageSize -> 150]
			 }
			 (*,{Dynamic[extrapt]}*)
			}, Alignment -> Center, Frame -> None]
		
		}, Spacer[10]]]
 ]