Color Imaging Functions Jun Hirabayashi (jun@hirax.net) 2009.07.24 - 2012.02.10 Functions Off[General::spell] $RecursionLimit=$IterationLimit=2000; (* 計算波長領域、および、グラフ表示などを行う場合に用いる波長分割幅 *) MinWL = 350; MaxWL = 800; divWL=2; 白色スペクトル関数 whiteLight[ x_ ] = 1.0; D65スペクトル関数 D65 = Interpolation[{{350,0.4491`},{351,0.4517456`},{352,0.45378880000000005`},{353,0.4553792`},{354,0.45666640000000003`},{355,0.45780000000000004`},{356,0.45892960000000005`},{357,0.4602048`},{358,0.4617752`},{359,0.46379040000000005`},{360,0.46640000000000004`},{361,0.47094400000000003`},{362,0.47608400000000006`},{363,0.48167200000000004`},{364,0.48756`},{365,0.4936`},{366,0.500268`},{367,0.5066360000000001`},{368,0.5124000000000001`},{369,0.517256`},{370,0.5209`},{371,0.5205960000000001`},{372,0.51908`},{373,0.516656`},{374,0.513628`},{375,0.5103`},{376,0.5071136`},{377,0.5042008`},{378,0.5018311999999999`},{379,0.5002744`},{380,0.49979999999999997`},{381,0.5028344`},{382,0.5069511999999999`},{383,0.5118808`},{384,0.5173536`},{385,0.5231`},{386,0.524028`},{387,0.525896`},{388,0.52964`},{389,0.536196`},{390,0.5465`},{391,0.5689792`},{392,0.5952056`},{393,0.6242424000000001`},{394,0.6551528000000001`},{395,0.687`},{396,0.7181976`},{397,0.7486208000000001`},{398,0.7774952`},{399,0.8040464`},{400,0.8275`},{401,0.8408864`},{402,0.8511752`},{403,0.8591408`},{404,0.8655576`},{405,0.8712000000000001`},{406,0.881028`},{407,0.890584`},{408,0.899596`},{409,0.907792`},{410,0.9148999999999999`},{411,0.9184720000000001`},{412,0.9209559999999999`},{413,0.922624`},{414,0.9237479999999999`},{415,0.9246`},{416,0.9279288`},{417,0.9309103999999999`},{418,0.9331976000000001`},{419,0.9344432`},{420,0.9343000000000001`},{421,0.9296464000000001`},{422,0.9236032000000001`},{423,0.9165168`},{424,0.9087336`},{425,0.9006000000000001`},{426,0.8898543999999999`},{427,0.8801032000000001`},{428,0.8723448`},{429,0.8675776000000001`},{430,0.8668000000000001`},{431,0.8789944`},{432,0.8951792000000001`},{433,0.9143568000000001`},{434,0.9355296`},{435,0.9577`},{436,0.9768432`},{437,0.9957455999999999`},{438,1.0141664000000001`},{439,1.0318648000000001`},{440,1.0486`},{441,1.062208`},{442,1.074852`},{443,1.086772`},{444,1.0982079999999999`},{445,1.1094`},{446,1.1233592000000001`},{447,1.1368616`},{448,1.1494544`},{449,1.1606848`},{450,1.1701000000000001`},{451,1.1736216000000002`},{452,1.1753288000000002`},{453,1.1756752000000001`},{454,1.1751144`},{455,1.1741`},{456,1.1754984000000002`},{457,1.1767471999999999`},{458,1.1776967999999999`},{459,1.1781976`},{460,1.1781000000000001`},{461,1.1760608000000001`},{462,1.1734224`},{463,1.1703336`},{464,1.1669432000000002`},{465,1.1634`},{466,1.1598016`},{467,1.1563608`},{468,1.1532392`},{469,1.1505984`},{470,1.1486`},{471,1.1486952`},{472,1.1494336`},{473,1.1506544`},{474,1.1521968`},{475,1.1539`},{476,1.1562656`},{477,1.1583048`},{478,1.1596912000000001`},{479,1.1600984`},{480,1.1592`},{481,1.1540616000000001`},{482,1.1476168`},{483,1.1401912`},{484,1.1321104000000002`},{485,1.1237000000000001`},{486,1.1153592`},{487,1.1073216000000001`},{488,1.0998944`},{489,1.0933848000000002`},{490,1.0881`},{491,1.0868016`},{492,1.0867288000000002`},{493,1.0875752`},{494,1.0890344`},{495,1.0908`},{496,1.0916728`},{497,1.0924624`},{498,1.0930856`},{499,1.0934591999999999`},{500,1.0935`},{501,1.0924624`},{502,1.0910912`},{503,1.0894688`},{504,1.0876776`},{505,1.0858`},{506,1.0844752`},{507,1.0830896`},{508,1.0815864`},{509,1.0799088000000001`},{510,1.078`},{511,1.0753488`},{512,1.0724664`},{513,1.0694096`},{514,1.0662352`},{515,1.063`},{516,1.0590376000000001`},{517,1.0553088`},{518,1.0520512000000002`},{519,1.0495024000000002`},{520,1.0479`},{521,1.0493792000000002`},{522,1.0518056`},{523,1.0549424`},{524,1.0585528`},{525,1.0624`},{526,1.0662888`},{527,1.0699304`},{528,1.0730776`},{529,1.0754832`},{530,1.0769`},{531,1.0751032`},{532,1.0723175999999999`},{533,1.0687904000000001`},{534,1.0647688`},{535,1.0605`},{536,1.0567528`},{537,1.0531224000000001`},{538,1.0497256`},{539,1.0466792`},{540,1.0441`},{541,1.0430392000000002`},{542,1.0424456`},{543,1.0422024`},{544,1.0421928`},{545,1.0423`},{546,1.042532`},{547,1.042616`},{548,1.0424039999999999`},{549,1.0417480000000001`},{550,1.0405`},{551,1.0373248`},{552,1.0335584`},{553,1.0293496`},{554,1.0248472`},{555,1.0202`},{556,1.0160943999999998`},{557,1.0120072`},{558,1.0079528`},{559,1.0039456`},{560,1.`},{561,0.9962520000000001`},{562,0.992564`},{563,0.98892`},{564,0.9853040000000001`},{565,0.9817`},{566,0.9775224`},{567,0.9734672000000001`},{568,0.9696608000000001`},{569,0.9662295999999999`},{570,0.9633`},{571,0.9620063999999999`},{572,0.9612152`},{573,0.9608008`},{574,0.9606376000000001`},{575,0.9606`},{576,0.9611096000000001`},{577,0.9613568000000001`},{578,0.9610792000000001`},{579,0.9600144`},{580,0.9579000000000001`},{581,0.9523744000000001`},{582,0.9457992000000001`},{583,0.9384368000000001`},{584,0.9305496`},{585,0.9224`},{586,0.9139528`},{587,0.9058423999999999`},{588,0.8984056`},{589,0.8919792`},{590,0.8869`},{591,0.8861992`},{592,0.8868455999999999`},{593,0.8885024`},{594,0.8908327999999999`},{595,0.8935`},{596,0.8950984`},{597,0.8966272`},{598,0.8980168000000001`},{599,0.8991975999999999`},{600,0.9001000000000001`},{601,0.9000944`},{602,0.8998112`},{603,0.8993208`},{604,0.8986936`},{605,0.898`},{606,0.8978351999999999`},{607,0.8976136`},{608,0.8972743999999999`},{609,0.8967568`},{610,0.8959999999999999`},{611,0.89446`},{612,0.89268`},{613,0.8907200000000001`},{614,0.8886400000000001`},{615,0.8865000000000001`},{616,0.8850032`},{617,0.8834056000000001`},{618,0.8816064`},{619,0.8795048`},{620,0.877`},{621,0.8731816000000001`},{622,0.8689608`},{623,0.8644392`},{624,0.8597184`},{625,0.8549`},{626,0.8497272`},{627,0.8447496`},{628,0.8401584`},{629,0.8361448`},{630,0.8329000000000001`},{631,0.8321448000000001`},{632,0.8321584`},{633,0.8327496`},{634,0.8337272`},{635,0.8349`},{636,0.8359711999999999`},{637,0.8368816`},{638,0.8374664`},{639,0.8375608`},{640,0.8370000000000001`},{641,0.8343008000000001`},{642,0.8309464`},{643,0.8271016`},{644,0.8229312000000001`},{645,0.8186`},{646,0.8143208`},{647,0.8101984`},{648,0.8063856`},{649,0.8030352000000001`},{650,0.8003`},{651,0.7995584000000001`},{652,0.7994312000000001`},{653,0.7997648000000002`},{654,0.8004056`},{655,0.8012`},{656,0.8010760000000001`},{657,0.8010280000000001`},{658,0.801132`},{659,0.8014640000000001`},{660,0.8020999999999999`},{661,0.8037272`},{662,0.8056576`},{663,0.8078144`},{664,0.8101208`},{665,0.8125`},{666,0.8155344`},{667,0.8183232`},{668,0.8206248`},{669,0.8221976000000001`},{670,0.8228`},{671,0.8202544`},{672,0.8167392`},{673,0.8124968`},{674,0.8077696000000001`},{675,0.8028000000000001`},{676,0.7995296000000001`},{677,0.7960768`},{678,0.7922592`},{679,0.7878944`},{680,0.7828`},{681,0.7753344`},{682,0.7671392`},{683,0.7583968`},{684,0.7492896`},{685,0.74`},{686,0.7297664`},{687,0.7199512`},{688,0.7109728`},{689,0.7032496`},{690,0.6972`},{691,0.6965928`},{692,0.6976584`},{693,0.6999776`},{694,0.7031312`},{695,0.7067`},{696,0.7084471999999999`},{697,0.7102256`},{698,0.7120704000000001`},{699,0.7140168`},{700,0.7161`},{701,0.7186336`},{702,0.7213048000000001`},{703,0.7240792`},{704,0.7269224`},{705,0.7298`},{706,0.7350168000000001`},{707,0.7396144`},{708,0.7429736`},{709,0.7444752`},{710,0.7434999999999999`},{711,0.7344784`},{712,0.7229791999999999`},{713,0.7096208`},{714,0.6950216`},{715,0.6798000000000001`},{716,0.6636784`},{717,0.6483952000000001`},{718,0.6347928`},{719,0.6237136000000001`},{720,0.616`},{721,0.6192272`},{722,0.6258216`},{723,0.6349424`},{724,0.6457487999999999`},{725,0.6574`},{726,0.6661912`},{727,0.6748616`},{728,0.6832864`},{729,0.6913408`},{730,0.6989`},{731,0.7048439999999999`},{732,0.710292`},{733,0.715368`},{734,0.720196`},{735,0.7249`},{736,0.732772`},{737,0.739976`},{738,0.7458440000000001`},{739,0.749708`},{740,0.7509`},{741,0.7434080000000001`},{742,0.733244`},{743,0.721076`},{744,0.707572`},{745,0.6934`},{746,0.6828056000000001`},{747,0.6719848`},{748,0.6607112`},{749,0.6487584`},{750,0.6359`},{751,0.6201016`},{752,0.6033968000000001`},{753,0.5860112000000001`},{754,0.5681704`},{755,0.5501`},{756,0.5269152`},{757,0.5052296`},{758,0.4865464`},{759,0.4723688`},{760,0.4642`},{761,0.47556240000000005`},{762,0.4929352`},{763,0.5148168`},{764,0.5397056`},{765,0.5661`},{766,0.5903096`},{767,0.6135688`},{768,0.6349232`},{769,0.6534184000000001`},{770,0.6681`},{771,0.6703784`},{772,0.6688432000000001`},{773,0.6644488`},{774,0.6581496`},{775,0.6509`},{776,0.6467808`},{777,0.6428384`},{778,0.6392456`},{779,0.6361752`},{780,0.6338`},{781,0.6336784`},{782,0.6342512`},{783,0.6353448`},{784,0.6367856000000001`},{785,0.6384000000000001`},{786,0.6402416000000001`},{787,0.6418528000000001`},{788,0.6430032`},{789,0.6434624`},{790,0.643`},{791,0.6395456`},{792,0.6351688`},{793,0.6300992`},{794,0.6245664`},{795,0.6188`},{796,0.6130296000000001`},{797,0.6074848`},{798,0.6023952`},{799,0.5979904`},{800,0.5945`}}] ; CIE1986 xCIE1986 = Interpolation[{ {350,0},{355,0},{360,0},{365,0},{370,0},{375,0},{380,0.0014},{385,0.0022},{390,0.0042},{395,0.0076},{400,0.0143},{405,0.0232},{410,0.0435},{415,0.0776},{420,0.1344},{425,0.2148},{430,0.2839},{435,0.3285},{440,0.3483},{445,0.3481},{450,0.3362},{455,0.3187},{460,0.2908},{465,0.2511},{470,0.1954},{475,0.1421},{480,0.0956},{485,0.058},{490,0.032},{495,0.0147},{500,0.0049},{505,0.0024},{510,0.0093},{515,0.0291},{520,0.0633},{525,0.1096},{530,0.1655},{535,0.2257},{540,0.2904},{545,0.3597},{550,0.4334},{555,0.5121},{560,0.5945},{565,0.6784},{570,0.7621},{575,0.8425},{580,0.9163},{585,0.9786},{590,1.0263},{595,1.0567},{600,1.0622},{605,1.0456},{610,1.0026},{615,0.9384},{620,0.8544},{625,0.7514},{630,0.6424},{635,0.5419},{640,0.4479},{645,0.3608},{650,0.2835},{655,0.2187},{660,0.1649},{665,0.1212},{670,0.0874},{675,0.0636},{680,0.0468},{685,0.0329},{690,0.0227},{695,0.0158},{700,0.0114},{705,0.0081},{710,0.0058},{715,0.0041},{720,0.0029},{725,0.002},{730,0.0014},{735,0.001},{740,0.0007},{745,0.0005},{750,0.0003},{755,0.0002},{760,0.0002},{765,0.0001},{770,0.0001},{775,0.0001},{780,0},{785,0},{790,0},{795,0},{800,0} }]; yCIE1986 = Interpolation[{{350,0},{355,0},{360,0},{365,0},{370,0},{375,0},{380,0},{385,0.0001},{390,0.0001},{395,0.0002},{400,0.0004},{405,0.0006},{410,0.0012},{415,0.0022},{420,0.004},{425,0.0073},{430,0.0116},{435,0.0168},{440,0.023},{445,0.0298},{450,0.038},{455,0.048},{460,0.06},{465,0.0739},{470,0.091},{475,0.1126},{480,0.139},{485,0.1693},{490,0.208},{495,0.2586},{500,0.323},{505,0.4073},{510,0.503},{515,0.6082},{520,0.71},{525,0.7932},{530,0.862},{535,0.9149},{540,0.954},{545,0.9803},{550,0.995},{555,1},{560,0.995},{565,0.9786},{570,0.952},{575,0.9154},{580,0.87},{585,0.8163},{590,0.757},{595,0.6949},{600,0.631},{605,0.5668},{610,0.503},{615,0.4412},{620,0.381},{625,0.321},{630,0.265},{635,0.217},{640,0.175},{645,0.1382},{650,0.107},{655,0.0816},{660,0.061},{665,0.0446},{670,0.032},{675,0.0232},{680,0.017},{685,0.0119},{690,0.0082},{695,0.0057},{700,0.0041},{705,0.0029},{710,0.0021},{715,0.0015},{720,0.001},{725,0.0007},{730,0.0005},{735,0.0004},{740,0.0002},{745,0.0002},{750,0.0001},{755,0.0001},{760,0.0001},{765,0},{770,0},{775,0},{780,0},{785,0},{790,0},{795,0},{800,0}} ]; zCIE1986 = Interpolation[{{350,0},{355,0},{360,0},{365,0},{370,0},{375,0},{380,0.0065},{385,0.0105},{390,0.0201},{395,0.0362},{400,0.0679},{405,0.1102},{410,0.2074},{415,0.3713},{420,0.6456},{425,1.0391},{430,1.3856},{435,1.623},{440,1.7471},{445,1.7826},{450,1.7721},{455,1.7441},{460,1.6692},{465,1.5281},{470,1.2876},{475,1.0419},{480,0.813},{485,0.6162},{490,0.4652},{495,0.3533},{500,0.272},{505,0.2123},{510,0.1582},{515,0.1117},{520,0.0782},{525,0.0573},{530,0.0422},{535,0.0298},{540,0.0203},{545,0.0134},{550,0.0087},{555,0.0057},{560,0.0039},{565,0.0027},{570,0.0021},{575,0.0018},{580,0.0017},{585,0.0014},{590,0.0011},{595,0.001},{600,0.0008},{605,0.0006},{610,0.0003},{615,0.0002},{620,0.0002},{625,0.0001},{630,0},{635,0},{640,0},{645,0},{650,0},{655,0},{660,0},{665,0},{670,0},{675,0},{680,0},{685,0},{690,0},{695,0},{700,0},{705,0},{710,0},{715,0},{720,0},{725,0},{730,0},{735,0},{740,0},{745,0},{750,0},{755,0},{760,0},{765,0},{770,0},{775,0},{780,0},{785,0},{790,0},{795,0},{800,0}} ]; Plot[{xCIE1986[x],yCIE1986[x],zCIE1986[x]},{x,350,750},Filling->Axis, FillingStyle->Directive[Opacity[0.5],Gray]] CIE1986 X Y Z 刺激値計算関数 X1986[ spector_] := Block[ {$Messages={}}, NIntegrate[ spector[x] xCIE1986[x], {x,MinWL,MaxWL},WorkingPrecision->12, MaxRecursion->30] ]; Y1986[ spector_] := Block[{$Messages={}}, NIntegrate[ spector[x] yCIE1986[x], {x,MinWL,MaxWL},WorkingPrecision->12, MaxRecursion->30] ]; Z1986[ spector_] := Block[{$Messages={}}, NIntegrate[ spector[x] zCIE1986[x], {x,MinWL,MaxWL},WorkingPrecision->12, MaxRecursion->30] ]; XYZ1986[ spector_ ] := { X1986[spector], Y1986[spector], Z1986[spector] } 基準照明設定関数( 返値は{ k, Xn, Yn, Zn } ) SetRefLight[ lightSpector_]:= (RefLight[x_] := lightSpector[x]; Xn0 = N[ X1986[ RefLight],4 ]; Yn0 = N[ Y1986[ RefLight],4]; Zn0 = N[ Z1986[ RefLight],4 ]; {k = N[100 / Yn0, 4], Xn = N[Xn0* k, 4], Zn = N[Zn0 * k, 4], Yn = N[Yn0 * k, 4]} ) Lab計算関数 ( 返値は{ L*, a*, b* } ) lab[spector_]:=N[ {116( k Y1986[ spector ]/Yn)^(1/3)-16, 500 (( k X1986[ spector ]/Xn)^(1/3)-( k Y1986[ spector ]/Yn)^(1/3)), 200 (( k Y1986[ spector ]/Yn)^(1/3)-( k Z1986[ spector ]/Zn)^(1/3))} , 4] 彩度計算関数 ( 返値は{ c* } ) c[spector_]:=N[ Sqrt[ (500 (( k X1986[ spector ]/Xn)^(1/3)-( k Y1986[ spector ]/Yn)^(1/3)))^2+ (200 (( k Y1986[ spector ]/Yn)^(1/3)-( k Z1986[ spector ]/Zn)^(1/3)))^2], 4] 減衰色(スペクトル)関数 idealCyanFilter = Interpolation[ {{350,1-1},{400,1-1},{420,1-1},{440,1-1},{460,1-1},{480,1-1},{500,1-1},{520,1-1},{540,1-1},{560,1-1},{580,1-1},{600,1-0},{620,1-0},{640,1-0},{660,1-0},{680,1-0},{700,1-0},{800,1-0}}, InterpolationOrder->1]; idealMagentaFilter = Interpolation[ { {350,1-1},{400,1-1},{420,1-1},{440,1-1},{460,1-1},{480,1-1},{500,1-0},{520,1-0},{540,1-0},{560,1-0},{580,1-0},{600,1-0},{620,1-1},{640,1-1},{660,1-1},{680,1-1},{700,1-1},{800,1-1} }, InterpolationOrder->1]; idealYellowFilter = Interpolation[ { {350,1-0},{400,1-0},{420,1-0},{440,1-0},{460,1-0},{480,1-0},{500,1-0},{520,1-0},{540,1-1},{560,1-1},{580,1-1},{600,1-1},{620,1-1},{640,1-1},{660,1-1},{680,1-1},{700,1-1},{800,1-1} }, InterpolationOrder->1 ]; idealBlackFilter[x_] := 1; cyanFilter = Interpolation[ {{350.000000,0.159000},{400.000000,0.159000}, {420.000000,0.089300}, {440.000000,0.052400}, {460.000000,0.031600}, {480.000000,0.023700}, {500.000000,0.024300}, {520.000000,0.042500}, {540.000000,0.098300}, {560.000000,0.237800}, {580.000000,0.424700}, {600.000000,0.543700}, {620.000000,0.607800}, {640.000000,0.552400}, {660.000000,0.445600}, {680.000000,0.439700}, {700.000000,0.517100}, {800,0.517100}}, InterpolationOrder->1]; magentaFilter = Interpolation[ {{350.000000,0.149900},{400.000000,0.149900}, {420.000000,0.135000}, {440.000000,0.124000}, {460.000000,0.143500}, {480.000000,0.196300}, {500.000000,0.276800}, {520.000000,0.428100}, {540.000000,0.568700}, {560.000000,0.644900}, {580.000000,0.596700}, {600.000000,0.133100}, {620.000000,0.042500}, {640.000000,0.021700}, {660.000000,0.016800}, {680.000000,0.014500}, {700.000000,0.009200}, {800.000000,0.009200}}, InterpolationOrder->1]; magentaFilter = Interpolation[ {{350.000000,0.149900},{400.000000,0.149900}, {420.000000,0.135000}, {440.000000,0.124000}, {460.000000,0.143500}, {480.000000,0.196300}, {500.000000,0.276800}, {520.000000,0.428100}, {540.000000,0.568700}, {560.000000,0.644900}, {580.000000,0.596700}, {600.000000,0.133100}, {620.000000,0.042500}, {640.000000,0.021700}, {660.000000,0.016800}, {680.000000,0.014500}, {700.000000,0.009200}, {800.000000,0.009200}}, InterpolationOrder->1]; yellowFilter = Interpolation[ {{350.000000,0.668600},{400.000000,0.668600}, {420.000000,0.923400}, {440.000000,0.9900000}, {460.000000,0.901500}, {480.000000,0.644100}, {500.000000,0.180500}, {520.000000,0.072200}, {540.000000,0.044200}, {560.000000,0.031100}, {580.000000,0.022100}, {600.000000,0.018300}, {620.000000,0.013500}, {640.000000,0.009100}, {660.000000,0.008600}, {680.000000,0.008200}, {700.000000,0.004700}, {800.000000,0.004700}}, InterpolationOrder->1]; grayFilter[x_] := 0.99; 光色(スペクトル)関数 blackLight[x_] = 0 ; redLight[x_] =1.697085334713303` * ( 0.41844 xCIE1986[x] -0.15866 yCIE1986[x] -0.08283 zCIE1986[x]); greenLight[x_] = 5.087234117636988` * ( -0.09117 xCIE1986[x] +0.25242 yCIE1986[x] +0.01570 zCIE1986[x]); blueLight[x_] = 3.846060603242237` * (0.00092 xCIE1986[x] -0.00255 yCIE1986[x] +0.17858 zCIE1986[x]); idealCyanLight=(1-idealCyanFilter [#])&; idealMagentaLight=(1-idealMagentaFilter[#])&; idealYellowLight=(1-idealYellowFilter[#])&; idealBlackLight[x_] := 0; cyanLight=(1-cyanFilter[#])&; magentaLight=(1-cyanFilter[#])&; magentaLight=(1-magentaFilter[#])&; yellowLight=(1-yellowFilter[#])&; Lambert-Beer則による透過光関数 (滅法混色) transmissionLight[ sourceLight_, layerSpector_, thinkness_ ] := Function[ {x}, sourceLight[x] (1-layerSpector[x])^(thinkness) ]; 色近似関数 spectorFitting[s_, f1_, f2_, f3_] := {c1,c2,c3} /. NMinimize[ {Apply[Plus, Table[ Abs[ s[x] - c1 f1[x] - c2 f2[x] - c3 f3[x] ], {x,MinWL+divWL,MaxWL-divWL ,divWL}] ] ,c1>0, c2>0, c3>0}, {c1,c2,c3} ,AccuracyGoal -> 6, PrecisionGoal -> 6,MaxIterations -> 200][[2]] simpleRGB[s_]:=Clip[Re[{s[700],s[546],s[436]}],{0,1}] (* rgb=spectorFitting[ (D65[#])&,redLight,greenLight,blueLight] *) fittingSpector[s_, f1_, f2_, f3_] :=( pars = {c1,c2,c3} /. NMinimize[ {Apply[Plus, Table[ Abs[ s[x] - c1 f1[x] - c2 f2[x] - c3 f3[x] ], {x,MinWL+divWL,MaxWL-divWL ,divWL}] ] ,c1>0, c2>0, c3>0}, {c1,c2,c3} ,AccuracyGoal -> 6, PrecisionGoal -> 6,MaxIterations -> 200][[2]]; pars . {f1[#],f2[#],f3[#]}& ) 色表示関数 spectorColor[wl_]:= RGBColor[ Clip[ 3.240479 xCIE1986 [wl] -1.537150 yCIE1986 [wl] -0.498535 zCIE1986 [wl],{0,1}] , Clip[-0.969256 xCIE1986 [wl] +1.875992 yCIE1986 [wl] +0.041556 zCIE1986 [wl],{0,1}] , Clip[+0.055648 xCIE1986 [wl] -0.204043 yCIE1986 [wl] +1.057311 zCIE1986 [wl] ,{0,1}] ]; spectorPlot[s_] := BarChart[ Table[ s[x],{x,MinWL+50,MaxWL-100 ,divWL}], GridLines->Automatic, Frame->True, FrameLabel->{"Wave Length","Intensity"}, FrameTicks->{None,Automatic}, ChartLabels->Table[ If[ Mod[x,50]==0,x,""],{x,MinWL+divWL,MaxWL-divWL ,divWL}], ChartStyle->Table[ spectorColor[x],{x,MinWL+divWL+50,MaxWL-divWL-50 ,divWL}], BarSpacing->-0.2, (*ChartStyle->EdgeForm[None],*) ChartBaseStyle->{Opacity[1.0],EdgeForm[None]}, Background->GrayLevel[1], PlotRange->{0,1.2}] (* グラフ色表示用 のため面倒な計算は割愛版 *) lab2xyz[lab_]:=( Module[ {x,y,z}, y=(lab[[1]]+16)/116; x=lab[[2]] /500+y; z=y-lab[[3]] /200; N[{x,y,z}]*100 ] ) (* グラフ色表示用 のため面倒な計算は割愛版 *) xyz2rgb[xyz_]:=( Module[{x,y,z,r,g,b}, x=xyz[[1]]/100; y=xyz[[2]]/100; z=xyz[[3]]/100; r=x*3.2406+y*-1.5372+z*-0.4986; g=x*-0.9689+y*1.8758+z*0.0415; b=x*0.0557+y*-0.2040+z*1.0570; r=If[r>0.0031308,1.055*(r^(1/2.4))-0.055,12.92*r]*255; g=If[g>0.0031308,1.055*(g^(1/2.4))-0.055,12.92*g]*255; b=If[b>0.0031308,1.055*(b^(1/2.4))-0.055,12.92*b]*255; N[{r,g,b}] ] ) (* グラフ色表示用 のため面倒な計算は割愛版 *) lab2rgb[lab_]:=xyz2rgb[ lab2xyz[lab] ] <<"PolyhedronOperations`" spectorLabPlot[spector_]:=( Module[ {labval,rgbval}, labval=lab[spector]; rgbval=Clip[Re[{spector[700],spector[546],spector[436]}],{0,1}]; Show[ Graphics3D[ { RGBColor[ rgbval[[1]], rgbval[[2]], rgbval[[3]] ], Cuboid[ {labval[[1]]-2.5,labval[[2]]-5,labval[[3]]-5}, {labval[[1]]+2.5,labval[[2]]+5,labval[[3]]+5} ] } ], Axes->True, AxesLabel->{"L*", "a*", "b*"}, FaceGrids->All, BoxRatios->{ 1, 1, 1 }, PlotRange->{{0,100},{-100,100},{-100,100}}, ViewPoint->{9.000, 0.000, 0.000},Lighting -> "Neutral" ] ] ) labPlot[labs_] := Show[ Graphics3D[ Table[ { RGBColor[ xyz2rgb[ lab2xyz[labs[[i]]] ] /255 ], EdgeForm[Thin], Cuboid[ {labs[[i]][[1]]-5/4,labs[[i]][[2]]-5/2,labs[[i]][[3]]-5/2}, {labs[[i]][[1]]+5/4,labs[[i]][[2]]+5/2,labs[[i]][[3]]+5/2} ]} , {i, 1, Length[labs] }] ], Axes->True, AxesLabel->{"L*", "a*", "b*"}, FaceGrids->All, BoxRatios->{ 1, 1, 1 }, PlotRange->{{0,100},{-100,100},{-100,100}}, ViewPoint->{9.000, 0.000, 0.000} ,Lighting -> "Neutral"] SetRefLight[ D65 ];