Цветовой круг CIE Lab (LCh) с верными углами по hue (D50, 2°)

Полезные скрипты
Ответить
Аватара пользователя
mihas
Администратор
Сообщения: 1454
Зарегистрирован: 18 авг 2004, 16:58
Откуда: Москва
Контактная информация:

Цветовой круг CIE Lab (LCh) с верными углами по hue (D50, 2°)

Сообщение mihas »

Результат работы скрипта
Результат работы скрипта
• 93.42 КБ • 8055 просмотров
Для оформления проекции ab в CIE Lab координатах нарисовал с помощью чистого php и спектрального калькулятора правильный цветовой круг, вот код скрипта для любознательных.
В работе скрипт можете посмотреть по ссылке: https://cielab.xyz/cyrclesRGB.php там же и html часть скрипта c формой отправки любых колориметрических данных можно посмотреть.

Код: Выделить всё

<?php
//Автор Михаил Сартаков, написано 2016.11.21
if (isset($_POST['r'])) {
$r = $_POST['r'];
$g =  $_POST['g'];
$b =  $_POST['b'];
$red = explode(',', $r);
$green = explode(',', $g);
$blue = explode(',', $b);
$a = array(50.0,49.9925,49.9692,49.9315,49.8783,49.8098,49.7261,49.6275,49.5135,49.3844,49.2403,49.0813,48.9076,48.7185,48.5149,48.2964,48.0631,47.8154,47.5529,47.2761,46.9848,46.6788,46.3589,46.0252,45.6771,45.3152,44.9395,44.5502,44.1473,43.7312,43.3012,42.8583,42.4023,41.9337,41.4518,40.9576,40.4508,39.9318,39.4003,38.8573,38.3023,37.7358,37.1574,36.5677,35.9669,35.3553,34.7331,34.1000,33.4565,32.8031,32.1396,31.4660,30.7832,30.0906,29.3890,28.6789,27.9594,27.2318,26.4961,25.7520,25.0000,24.2405,23.4734,22.6993,21.9185,21.1309,20.3367,19.5367,18.7302,17.9184,17.1011,16.2785,15.4510,14.6186,13.7818,12.9409,12.0960,11.2476,10.3956,9.5405,8.6826,7.8215,6.9586,6.0935,5.2264,4.3577,3.4878,2.6168,1.7450,0.8726,-0.0000,-0.8725,-1.7449,-2.6167,-3.4878,-4.3578,-5.2265,-6.0936,-6.9586,-7.8218,-8.6825,-9.5404,-10.3955,-11.2474,-12.0960,-12.9410,-13.7817,-14.6186,-15.4508,-16.2784,-17.1011,-17.9184,-18.7303,-19.5365,-20.3370,-21.1309,-21.9185,-22.6995,-23.4737,-24.2405,-25.0001,-25.7518,-26.4958,-27.2319,-27.9598,-28.6789,-29.3893,-30.0908,-30.7831,-31.4661,-32.1394,-32.8030,-33.4564,-34.0999,-34.7329,-35.3555,-35.9671,-36.5676,-37.1571,-37.7353,-38.3023,-38.8572,-39.4008,-39.9319,-40.4510,-40.9577,-41.4520,-41.9334,-42.4023,-42.8584,-43.3011,-43.7308,-44.1475,-44.5504,-44.9397,-45.3154,-45.6774,-46.0251,-46.3591,-46.6791,-46.9846,-47.2760,-47.5529,-47.8151,-48.0632,-48.2964,-48.5147,-48.7185,-48.9075,-49.0813,-49.2404,-49.3846,-49.5134,-49.6271,-49.7260,-49.8097,-49.8782,-49.9315,-49.9696,-49.9924,-50.0000,-49.9924,-49.9695,-49.9315,-49.8782,-49.8099,-49.7262,-49.6274,-49.5133,-49.3844,-49.2403,-49.0813,-48.9073,-48.7183,-48.5149,-48.2964,-48.0630,-47.8152,-47.5528,-47.2760,-46.9846,-46.6790,-46.3591,-46.0253,-45.6773,-45.3153,-44.9396,-44.5503,-44.1472,-43.7311,-43.3011,-42.8582,-42.4026,-41.9337,-41.4519,-40.9576,-40.4511,-39.9318,-39.4006,-38.8572,-38.3023,-37.7354,-37.1571,-36.5675,-35.9671,-35.3553,-34.7330,-34.0999,-33.4565,-32.8030,-32.1394,-31.4660,-30.7831,-30.0907,-29.3893,-28.6786,-27.9596,-27.2322,-26.4960,-25.7519,-25.0000,-24.2407,-23.4735,-22.6993,-21.9187,-21.1310,-20.3368,-19.5368,-18.7303,-17.9183,-17.1013,-16.2784,-15.4509,-14.6184,-13.7820,-12.9409,-12.0961,-11.2477,-10.3952,-9.5402,-8.6826,-7.8220,-6.9585,-6.0934,-5.2264,-4.3574,-3.4878,-2.6165,-1.7448,-0.8725,0.0001,0.8723,1.7445,2.6169,3.4880,4.3580,5.2265,6.0930,6.9586,7.8215,8.6820,9.5404,10.3953,11.2476,12.0955,12.9406,13.7818,14.6189,15.4503,16.2788,17.1014,17.9183,18.7304,19.5366,20.3362,21.1303,21.9189,22.6996,23.4737,24.2403,25.0001,25.7517,26.4961,27.2326,27.9604,28.6790,29.3898,30.0909,30.7830,31.4657,32.1401,32.8032,33.4561,34.1005,34.7333,35.3551,35.9675,36.5680,37.1573,37.7353,38.3018,38.8573,39.4005,39.9317,40.4509,40.9575,41.4520,41.9335,42.4028,42.8586,43.3011,43.7308,44.1471,44.5503,44.9397,45.3155,45.6770,46.0254,46.3590,46.6786,46.9845,47.2760,47.5531,47.8154,48.0629,48.2964,48.5147,48.7184,48.9074,49.0815,49.2402,49.3846,49.5133,49.6276,49.7259,49.8098,49.8784,49.9317,49.9696,49.9925,50.0);
$b = array(0.0,0.8725,1.7450,2.6169,3.4877,4.3578,5.2264,6.0935,6.9587,7.8217,8.6825,9.5404,10.3954,11.2474,12.0961,12.9410,13.7819,14.6185,15.4508,16.2783,17.1009,17.9183,18.7304,19.5365,20.3370,21.1308,21.9186,22.6994,23.4737,24.2403,25.0002,25.7521,26.4958,27.2319,27.9595,28.6787,29.3892,30.0907,30.7833,31.4662,32.1393,32.8027,33.4567,34.0997,34.7332,35.3554,35.9669,36.5677,37.1571,37.7357,38.3020,38.8573,39.4004,39.9319,40.4508,40.9578,41.4518,41.9336,42.4024,42.8584,43.3012,43.7310,44.1474,44.5505,44.9396,45.3153,45.6772,46.0253,46.3591,46.6791,46.9845,47.2760,47.5527,47.8152,48.0631,48.2962,48.5147,48.7185,48.9074,49.0814,49.2403,49.3845,49.5134,49.6273,49.7262,49.8097,49.8782,49.9314,49.9695,49.9923,50.0000,49.9923,49.9696,49.9315,49.8781,49.8097,49.7262,49.6274,49.5135,49.3844,49.2404,49.0813,48.9073,48.7185,48.5147,48.2962,48.0631,47.8152,47.5528,47.2760,46.9846,46.6791,46.3591,46.0252,45.6773,45.3153,44.9397,44.5504,44.1474,43.7309,43.3013,42.8584,42.4023,41.9335,41.4519,40.9576,40.4508,39.9317,39.4006,38.8573,38.3023,37.7355,37.1573,36.5678,35.9670,35.3553,34.7329,34.1000,33.4565,32.8030,32.1394,31.4660,30.7830,30.0908,29.3892,28.6788,27.9596,27.2319,26.4960,25.7519,25.0000,24.2404,23.4736,22.6996,21.9186,21.1310,20.3368,19.5365,18.7303,17.9184,17.1010,16.2784,15.4509,14.6186,13.7819,12.9410,12.0960,11.2475,10.3956,9.5405,8.6824,7.8218,6.9587,6.0935,5.2264,4.3578,3.4878,2.6168,1.7450,0.8727,0.0001,-0.8727,-1.7450,-2.6168,-3.4878,-4.3578,-5.2264,-6.0934,-6.9586,-7.8217,-8.6824,-9.5404,-10.3956,-11.2476,-12.0961,-12.9409,-13.7819,-14.6186,-15.4508,-16.2784,-17.1010,-17.9184,-18.7303,-19.5366,-20.3368,-21.1309,-21.9185,-22.6995,-23.4736,-24.2405,-25.0000,-25.7520,-26.4959,-27.2319,-27.9596,-28.6788,-29.3892,-30.0907,-30.7831,-31.4660,-32.1394,-32.8029,-33.4566,-34.1000,-34.7329,-35.3553,-35.9670,-36.5677,-37.1573,-37.7356,-38.3021,-38.8573,-39.4006,-39.9318,-40.4508,-40.9576,-41.4519,-41.9335,-42.4024,-42.8584,-43.3013,-43.7309,-44.1474,-44.5504,-44.9397,-45.3154,-45.6773,-46.0252,-46.3591,-46.6790,-46.9846,-47.2760,-47.5528,-47.8153,-48.0631,-48.2964,-48.5148,-48.7184,-48.9074,-49.0814,-49.2404,-49.3844,-49.5134,-49.6273,-49.7260,-49.8098,-49.8781,-49.9315,-49.9696,-49.9925,-50.0001,-49.9923,-49.9695,-49.9315,-49.8783,-49.8098,-49.7262,-49.6272,-49.5135,-49.3843,-49.2402,-49.0812,-48.9073,-48.7185,-48.5147,-48.2962,-48.0631,-47.8152,-47.5526,-47.2760,-46.9847,-46.6789,-46.3594,-46.0252,-45.6772,-45.3153,-44.9396,-44.5505,-44.1475,-43.7308,-43.3013,-42.8584,-42.4025,-41.9337,-41.4522,-40.9575,-40.4510,-39.9319,-39.4006,-38.8572,-38.3022,-37.7357,-37.1571,-36.5679,-35.9671,-35.3553,-34.7331,-34.0999,-33.4565,-32.8029,-32.1393,-31.4660,-30.7831,-30.0908,-29.3892,-28.6787,-27.9596,-27.2319,-26.4961,-25.7520,-24.9999,-24.2405,-23.4735,-22.6995,-21.9185,-21.1310,-20.3368,-19.5366,-18.7303,-17.9183,-17.1010,-16.2785,-15.4509,-14.6187,-13.7817,-12.9409,-12.0961,-11.2476,-10.3955,-9.5405,-8.6823,-7.8218,-6.9587,-6.0934,-5.2265,-4.3578,-3.4878,-2.6169,-1.7450,-0.8726,0.0);
$image = imagecreatetruecolor(1002, 1002);
$white = imagecolorallocate($image,255,255,255);
$gray = imagecolorallocate($image,128,128,128);
imagefill($image, 1, 1, $white);
$color = array();
$values = array();
for ($e=0; $e < 360; $e++){
$color[$e] = imagecolorallocate($image,$red[$e],$green[$e],$blue[$e]);
$values[$e] = array(
			501,  501,   // Point 3 (x, y)
			intval($a[$e]*10+501),  intval($b[$e]*10+501),  // Point 1 (x, y)
			intval($a[$e+1]*10+501),  intval($b[$e+1]*10+501) // Point 2 (x, y)
			);
imagefilledpolygon($image, $values[$e], 3, $color[$e]);
}
imageflip($image, IMG_FLIP_VERTICAL);
$stringspct = "https://cielab.xyz/cyrclesRGB.php";
imagestring($image, 5, 695, 980, $stringspct, $gray);
// вывод изображения
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
exit;
} //isset post
?>
Собственно массивы $a и $b - это 360 координат на краю круга с шагом в 1° по hue, получены из LCh с одинаковым вектором радиуса Chroma по формуле LCh->Lab в спектральном калькуляторе.
Обычная геометрия перехода от длины и направления вектора к его координатам, но может кому-то будет любопытно:

Код: Выделить всё

function Lab2LCHab()
{
	LCHab.L = Lab.L;
	LCHab.C = Math.sqrt(Lab.a * Lab.a + Lab.b * Lab.b);
	LCHab.H = 180.0 * Math.atan2(Lab.b, Lab.a) / Math.PI;
	if (LCHab.H < 0.0)
	{
		LCHab.H += 360.0;
	}
}
И обратно:

Код: Выделить всё

function LCHab2Lab()
{
	Lab.L = LCHab.L;
	Lab.a = LCHab.C * Math.cos(LCHab.H * Math.PI / 180.0);
	Lab.b = LCHab.C * Math.sin(LCHab.H * Math.PI / 180.0);
}
Аватара пользователя
mihas
Администратор
Сообщения: 1454
Зарегистрирован: 18 авг 2004, 16:58
Откуда: Москва
Контактная информация:

Re: Цветовой круг CIE Lab (LCh) с верными углами по hue (D50, 2°)

Сообщение mihas »

Равноконтрастный по восприятию или Perceptual Uniformity цветовой круг можно построить в этой новой утилите: https://cielab.xyz/spectralcalc/Percept ... yrcle.html На вход подаем сырые данные цветового круга как есть для любой модели (в примере - в sRGB), на выходе получаем упорядоченные по delta E 2000 равноудаленные значения. Поскольку в дельте 2000 сумма отрезков AB и BC не равна отрезку AC - введена поправка к средней дельте между патчами, чтобы перебором поправки замыкать цветовой круг правильно тем же углом, что предпоследнее значение угла hue на входе в моем примере (в нем первое и последнее значение таблицы равны для просчете дельты по всему кругу, и в начале и в конце таблицы).
Ответить

Вернуться в «PHP»