%% Stiles and Burch (1955) 2-deg, RGB Color Matching Functions
RGB = [390, 1.83970e-003, -4.53930e-004, 1.21520e-002
395, 4.61530e-003, -1.04640e-003, 3.11100e-002
400, 9.62640e-003, -2.16890e-003, 6.23710e-002
405, 1.89790e-002, -4.43040e-003, 1.31610e-001
410, 3.08030e-002, -7.20480e-003, 2.27500e-001
415, 4.24590e-002, -1.25790e-002, 3.58970e-001
420, 5.16620e-002, -1.66510e-002, 5.23960e-001
425, 5.28370e-002, -2.12400e-002, 6.85860e-001
430, 4.42870e-002, -1.99360e-002, 7.96040e-001
435, 3.22200e-002, -1.60970e-002, 8.94590e-001
440, 1.47630e-002, -7.34570e-003, 9.63950e-001
445, -2.33920e-003, 1.36900e-003, 9.98140e-001
450, -2.91300e-002, 1.96100e-002, 9.18750e-001
455, -6.06770e-002, 4.34640e-002, 8.24870e-001
460, -9.62240e-002, 7.09540e-002, 7.85540e-001
465, -1.37590e-001, 1.10220e-001, 6.67230e-001
470, -1.74860e-001, 1.50880e-001, 6.10980e-001
475, -2.12600e-001, 1.97940e-001, 4.88290e-001
480, -2.37800e-001, 2.40420e-001, 3.61950e-001
485, -2.56740e-001, 2.79930e-001, 2.66340e-001
490, -2.77270e-001, 3.33530e-001, 1.95930e-001
495, -2.91250e-001, 4.05210e-001, 1.47300e-001
500, -2.95000e-001, 4.90600e-001, 1.07490e-001
505, -2.97060e-001, 5.96730e-001, 7.67140e-002
510, -2.67590e-001, 7.01840e-001, 5.02480e-002
515, -2.17250e-001, 8.08520e-001, 2.87810e-002
520, -1.47680e-001, 9.10760e-001, 1.33090e-002
525, -3.51840e-002, 9.84820e-001, 2.11700e-003
530, 1.06140e-001, 1.03390e+000, -4.15740e-003
535, 2.59810e-001, 1.05380e+000, -8.30320e-003
540, 4.19760e-001, 1.05120e+000, -1.21910e-002
545, 5.92590e-001, 1.04980e+000, -1.40390e-002
550, 7.90040e-001, 1.03680e+000, -1.46810e-002
555, 1.00780e+000, 9.98260e-001, -1.49470e-002
560, 1.22830e+000, 9.37830e-001, -1.46130e-002
565, 1.47270e+000, 8.80390e-001, -1.37820e-002
570, 1.74760e+000, 8.28350e-001, -1.26500e-002
575, 2.02140e+000, 7.46860e-001, -1.13560e-002
580, 2.27240e+000, 6.49300e-001, -9.93170e-003
585, 2.48960e+000, 5.63170e-001, -8.41480e-003
590, 2.67250e+000, 4.76750e-001, -7.02100e-003
595, 2.80930e+000, 3.84840e-001, -5.74370e-003
600, 2.87170e+000, 3.00690e-001, -4.27430e-003
605, 2.85250e+000, 2.28530e-001, -2.91320e-003
610, 2.76010e+000, 1.65750e-001, -2.26930e-003
615, 2.59890e+000, 1.13730e-001, -1.99660e-003
620, 2.37430e+000, 7.46820e-002, -1.50690e-003
625, 2.10540e+000, 4.65040e-002, -9.38220e-004
630, 1.81450e+000, 2.63330e-002, -5.53160e-004
635, 1.52470e+000, 1.27240e-002, -3.16680e-004
640, 1.25430e+000, 4.50330e-003, -1.43190e-004
645, 1.00760e+000, 9.66110e-005, -4.08310e-006
650, 7.86420e-001, -1.96450e-003, 1.10810e-004
655, 5.96590e-001, -2.63270e-003, 1.91750e-004
660, 4.43200e-001, -2.62620e-003, 2.26560e-004
665, 3.24100e-001, -2.30270e-003, 2.15200e-004
670, 2.34550e-001, -1.87000e-003, 1.63610e-004
675, 1.68840e-001, -1.44240e-003, 9.71640e-005
680, 1.20860e-001, -1.07550e-003, 5.10330e-005
685, 8.58110e-002, -7.90040e-004, 3.52710e-005
690, 6.02600e-002, -5.67650e-004, 3.12110e-005
695, 4.14800e-002, -3.92740e-004, 2.45080e-005
700, 2.81140e-002, -2.62310e-004, 1.65210e-005
705, 1.91170e-002, -1.75120e-004, 1.11240e-005
710, 1.33050e-002, -1.21400e-004, 8.69650e-006
715, 9.40920e-003, -8.57600e-005, 7.43510e-006
720, 6.51770e-003, -5.76770e-005, 6.10570e-006
725, 4.53770e-003, -3.90030e-005, 5.02770e-006
730, 3.17420e-003, -2.65110e-005, 4.12510e-006];
R = RGB(:,2);
G = RGB(:,3);
B = RGB(:,4);
%% CIE 1931 2-deg, XYZ Color Matching Functions
XYZ31 = [390, 0.004243000000, 0.000120000000, 0.020050010000
395, 0.007650000000, 0.000217000000, 0.036210000000
400, 0.014310000000, 0.000396000000, 0.067850010000
405, 0.023190000000, 0.000640000000, 0.110200000000
410, 0.043510000000, 0.001210000000, 0.207400000000
415, 0.077630000000, 0.002180000000, 0.371300000000
420, 0.134380000000, 0.004000000000, 0.645600000000
425, 0.214770000000, 0.007300000000, 1.039050100000
430, 0.283900000000, 0.011600000000, 1.385600000000
435, 0.328500000000, 0.016840000000, 1.622960000000
440, 0.348280000000, 0.023000000000, 1.747060000000
445, 0.348060000000, 0.029800000000, 1.782600000000
450, 0.336200000000, 0.038000000000, 1.772110000000
455, 0.318700000000, 0.048000000000, 1.744100000000
460, 0.290800000000, 0.060000000000, 1.669200000000
465, 0.251100000000, 0.073900000000, 1.528100000000
470, 0.195360000000, 0.090980000000, 1.287640000000
475, 0.142100000000, 0.112600000000, 1.041900000000
480, 0.095640000000, 0.139020000000, 0.812950100000
485, 0.057950010000, 0.169300000000, 0.616200000000
490, 0.032010000000, 0.208020000000, 0.465180000000
495, 0.014700000000, 0.258600000000, 0.353300000000
500, 0.004900000000, 0.323000000000, 0.272000000000
505, 0.002400000000, 0.407300000000, 0.212300000000
510, 0.009300000000, 0.503000000000, 0.158200000000
515, 0.029100000000, 0.608200000000, 0.111700000000
520, 0.063270000000, 0.710000000000, 0.078249990000
525, 0.109600000000, 0.793200000000, 0.057250010000
530, 0.165500000000, 0.862000000000, 0.042160000000
535, 0.225749900000, 0.914850100000, 0.029840000000
540, 0.290400000000, 0.954000000000, 0.020300000000
545, 0.359700000000, 0.980300000000, 0.013400000000
550, 0.433449900000, 0.994950100000, 0.008749999000
555, 0.512050100000, 1.000000000000, 0.005749999000
560, 0.594500000000, 0.995000000000, 0.003900000000
565, 0.678400000000, 0.978600000000, 0.002749999000
570, 0.762100000000, 0.952000000000, 0.002100000000
575, 0.842500000000, 0.915400000000, 0.001800000000
580, 0.916300000000, 0.870000000000, 0.001650001000
585, 0.978600000000, 0.816300000000, 0.001400000000
590, 1.026300000000, 0.757000000000, 0.001100000000
595, 1.056700000000, 0.694900000000, 0.001000000000
600, 1.062200000000, 0.631000000000, 0.000800000000
605, 1.045600000000, 0.566800000000, 0.000600000000
610, 1.002600000000, 0.503000000000, 0.000340000000
615, 0.938400000000, 0.441200000000, 0.000240000000
620, 0.854449900000, 0.381000000000, 0.000190000000
625, 0.751400000000, 0.321000000000, 0.000100000000
630, 0.642400000000, 0.265000000000, 0.000049999990
635, 0.541900000000, 0.217000000000, 0.000030000000
640, 0.447900000000, 0.175000000000, 0.000020000000
645, 0.360800000000, 0.138200000000, 0.000010000000
650, 0.283500000000, 0.107000000000, 0.000000000000
655, 0.218700000000, 0.081600000000, 0.000000000000
660, 0.164900000000, 0.061000000000, 0.000000000000
665, 0.121200000000, 0.044580000000, 0.000000000000
670, 0.087400000000, 0.032000000000, 0.000000000000
675, 0.063600000000, 0.023200000000, 0.000000000000
680, 0.046770000000, 0.017000000000, 0.000000000000
685, 0.032900000000, 0.011920000000, 0.000000000000
690, 0.022700000000, 0.008210000000, 0.000000000000
695, 0.015840000000, 0.005723000000, 0.000000000000
700, 0.011359160000, 0.004102000000, 0.000000000000
705, 0.008110916000, 0.002929000000, 0.000000000000
710, 0.005790346000, 0.002091000000, 0.000000000000
715, 0.004109457000, 0.001484000000, 0.000000000000
720, 0.002899327000, 0.001047000000, 0.000000000000
725, 0.002049190000, 0.000740000000, 0.000000000000
730, 0.001439971000, 0.000520000000, 0.000000000000];
X31 = XYZ31(:,2);
Y31 = XYZ31(:,3);
Z31 = XYZ31(:,4);
%% CIE 1964 2-deg, XYZ Color Matching Functions
XYZ64 =[390 0.0024 0.0003 0.0105 0.1803 0.0194 0.8003
395 0.0072 0.0008 0.0323 0.1795 0.0190 0.8015
400 0.0191 0.0020 0.0860 0.1784 0.0187 0.8029
405 0.0434 0.0045 0.1971 0.1771 0.0184 0.8045
410 0.0847 0.0088 0.3894 0.1755 0.0181 0.8064
415 0.1406 0.0145 0.6568 0.1732 0.0178 0.8090
420 0.2045 0.0214 0.9725 0.1706 0.0179 0.8115
425 0.2647 0.0295 1.2825 0.1679 0.0187 0.8134
430 0.3147 0.0387 1.5535 0.1650 0.0203 0.8147
435 0.3577 0.0496 1.7985 0.1622 0.0225 0.8153
440 0.3837 0.0621 1.9673 0.1590 0.0257 0.8153
445 0.3867 0.0747 2.0273 0.1554 0.0300 0.8146
450 0.3707 0.0895 1.9948 0.1510 0.0364 0.8126
455 0.3430 0.1063 1.9007 0.1459 0.0452 0.8088
460 0.3023 0.1282 1.7454 0.1389 0.0589 0.8022
465 0.2541 0.1528 1.5549 0.1295 0.0779 0.7926
470 0.1956 0.1852 1.3176 0.1152 0.1090 0.7758
475 0.1323 0.2199 1.0302 0.0957 0.1591 0.7452
480 0.0805 0.2536 0.7721 0.0728 0.2292 0.6980
485 0.0411 0.2977 0.5701 0.0452 0.3275 0.6273
490 0.0162 0.3391 0.4153 0.0210 0.4401 0.5389
495 0.0051 0.3954 0.3024 0.0073 0.5625 0.4302
500 0.0038 0.4608 0.2185 0.0056 0.6745 0.3199
505 0.0154 0.5314 0.1592 0.0219 0.7526 0.2256
510 0.0375 0.6067 0.1120 0.0495 0.8023 0.1482
515 0.0714 0.6857 0.0822 0.0850 0.8170 0.0980
520 0.1177 0.7618 0.0607 0.1252 0.8102 0.0646
525 0.1730 0.8233 0.0431 0.1664 0.7922 0.0414
530 0.2365 0.8752 0.0305 0.2071 0.7663 0.0267
535 0.3042 0.9238 0.0206 0.2436 0.7399 0.0165
540 0.3768 0.9620 0.0137 0.2786 0.7113 0.0101
545 0.4516 0.9822 0.0079 0.3132 0.6813 0.0055
550 0.5298 0.9918 0.0040 0.3473 0.6501 0.0026
555 0.6161 0.9991 0.0011 0.3812 0.6182 0.0007
560 0.7052 0.9973 0.0000 0.4142 0.5858 0.0000
565 0.7938 0.9824 0.0000 0.4469 0.5531 0.0000
570 0.8787 0.9556 0.0000 0.4790 0.5210 0.0000
575 0.9512 0.9152 0.0000 0.5096 0.4904 0.0000
580 1.0142 0.8689 0.0000 0.5386 0.4614 0.0000
585 1.0743 0.8256 0.0000 0.5654 0.4346 0.0000
590 1.1185 0.7774 0.0000 0.5900 0.4100 0.0000
595 1.1343 0.7204 0.0000 0.6116 0.3884 0.0000
600 1.1240 0.6583 0.0000 0.6306 0.3694 0.0000
605 1.0891 0.5939 0.0000 0.6471 0.3529 0.0000
610 1.0305 0.5280 0.0000 0.6612 0.3388 0.0000
615 0.9507 0.4618 0.0000 0.6731 0.3269 0.0000
620 0.8563 0.3981 0.0000 0.6827 0.3173 0.0000
625 0.7549 0.3396 0.0000 0.6898 0.3102 0.0000
630 0.6475 0.2835 0.0000 0.6955 0.3045 0.0000
635 0.5351 0.2283 0.0000 0.7010 0.2990 0.0000
640 0.4316 0.1798 0.0000 0.7059 0.2941 0.0000
645 0.3437 0.1402 0.0000 0.7103 0.2898 0.0000
650 0.2683 0.1076 0.0000 0.7137 0.2863 0.0000
655 0.2043 0.0812 0.0000 0.7156 0.2844 0.0000
660 0.1526 0.0603 0.0000 0.7168 0.2832 0.0000
665 0.1122 0.0441 0.0000 0.7179 0.2821 0.0000
670 0.0813 0.0318 0.0000 0.7187 0.2813 0.0000
675 0.0579 0.0226 0.0000 0.7193 0.2807 0.0000
680 0.0409 0.0159 0.0000 0.7198 0.2802 0.0000
685 0.0286 0.0111 0.0000 0.7200 0.2800 0.0000
690 0.0199 0.0077 0.0000 0.7202 0.2798 0.0000
695 0.0138 0.0054 0.0000 0.7203 0.2797 0.0000
700 0.0096 0.0037 0.0000 0.7204 0.2796 0.0000
705 0.0066 0.0026 0.0000 0.7203 0.2797 0.0000
710 0.0046 0.0018 0.0000 0.7202 0.2798 0.0000
715 0.0031 0.0012 0.0000 0.7201 0.2799 0.0000
720 0.0022 0.0008 0.0000 0.7199 0.2801 0.0000
725 0.0015 0.0006 0.0000 0.7197 0.2803 0.0000
730 0.0010 0.0004 0.0000 0.7195 0.2806 0.0000];
X64 = XYZ64(:,2);
Y64 = XYZ64(:,3);
Z64 = XYZ64(:,4);
% USGS Digital Spectral Library splib05a
% Clark et. al. 2003, USGS, Open File Report 03-395.
% Aspen Aspen-4 Yellow-Top W1R1Fa AREF
% 390 nm - 730 nm (missing values in 390 nm - 410 nm range set equal to 415 nm value by lrw)
A = [0.042278
0.042278
0.042278
0.042278
0.042278
0.042278
0.042278
0.044015
0.045321
0.048306
0.050449
0.051018
0.051967
0.053204
0.054561
0.056831
0.058147
0.059621
0.059657
0.060918
0.063285
0.069525
0.080278
0.101324
0.134686
0.180626
0.231896
0.278561
0.316194
0.344316
0.365316
0.380658
0.391904
0.400566
0.407088
0.412543
0.418508
0.422612
0.425715
0.428314
0.430876
0.433485
0.435482
0.437102
0.437413
0.437566
0.437001
0.436692
0.437509
0.438249
0.438182
0.436701
0.434592
0.431861
0.426331
0.415853
0.404854
0.398874
0.400010
0.412456
0.433544
0.451670
0.462577
0.468215
0.471071
0.472357
0.473164
0.473626
0.473908];
XYZ2RGB = [3.240479 -1.53715 -0.498535; -0.969256 1.875991 0.041556; 0.055648 -0.204043 1.057311];
% CIE XYZ computed using CIE 1964 color matching functions
% CIE XYZ linear transformed to CIE Rec. 709 RGB using XYZ2RGB
% CIE Rec. 709 RGB to non-linear RGB using 0.45 power function gamma correction
% See http://www.poynton.com/notes/colour_and_gamma/
% USGS Digital Spectral Library splib05a
% Clark et. al. 2003, USGS, Open File Report 03-395.
% Flower Petunia-1 W1R1Fa AREF
% 390 nm - 730 nm
P = [0.0358210
0.0476500
0.0619550
0.0734340
0.0834790
0.0916360
0.0961370
0.0976420
0.0968610
0.0943520
0.0908830
0.0865940
0.0815980
0.0759210
0.0692710
0.0619080
0.0540030
0.0459040
0.0382170
0.0313990
0.0253430
0.0203930
0.0165670
0.0136620
0.0115510
0.0101600
0.0093250
0.0087810
0.0085310
0.0084350
0.0085100
0.0087360
0.0092010
0.0100260
0.0114580
0.0138950
0.0179350
0.0244740
0.0345590
0.0491200
0.0686950
0.0946340
0.1240290
0.1551250
0.1863180
0.2174440
0.2467840
0.2720830
0.2938640
0.3132150
0.3298740
0.3428580
0.3527110
0.3611530
0.3678730
0.3717890
0.3736740
0.3755270
0.3782440
0.3836580
0.3935560
0.4074380
0.4220780
0.4368930
0.4515990
0.4660660
0.4794410
0.4952440
0.5093150];
% CIE XYZ computed using CIE 1964 color matching functions
% CIE XYZ linear transformed to CIE Rec. 709 RGB using XYZ2RGB
% CIE Rec. 709 RGB to non-linear RGB using 0.45 power function gamma correction
% See http://www.poynton.com/notes/colour_and_gamma/