DeltaE CIE2000 구현

DeltaE_CIE2000 구현
DeltaE_CIE00 구현
CIEDE2000에 따른 색상 차이 계산

1 소스 코드[ | ]

<?php
function xmp_print($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }
function deltaE_CIE00($Lab1, $Lab2) {
	list($L1, $a1, $b1) = $Lab1;
	list($L2, $a2, $b2) = $Lab2;

	$C1 = sqrt( pow($a1,2) + pow($b1,2) );
	$C2 = sqrt( pow($a2,2) + pow($b2,2) );
	$barL = ($L1 + $L2) / 2;
	$barC = ($C1 + $C2) / 2;

	$G = 0.5 * (1 - sqrt( pow($barC,7) / (pow($barC,7) + 6103515625) ));
	$a1p = $a1 * (1+$G);
	$a2p = $a2 * (1+$G);
	$C1p = sqrt( pow($a1p,2) + pow($b1,2) );
	$C2p = sqrt( pow($a2p,2) + pow($b2,2) );
	$barCp = ($C1p + $C2p) / 2;
	$h1p = rad2deg(atan2($b1, $a1p));
	if( $h1p < 0 ) $h1p += 360;
	$h2p = rad2deg(atan2($b2, $a2p));
	if( $h2p < 0 ) $h2p += 360;
	$barHp = abs($h1p-$h2p) > 180 ? ($h1p+$h2p+360)/2 : ($h1p+$h2p)/2;
	$T = 1 - 0.17 * cos(deg2rad($barHp - 30)) + 0.24*cos(deg2rad(2 * $barHp)) + 0.32*cos(deg2rad(3 * $barHp + 6)) - 0.2*cos(deg2rad(4 * $barHp - 63));
	$deltaHp = $h2p - $h1p;
	if( abs($deltaHp) > 180) {
		if ($h2p <= $h1p) $deltaHp += 360;
		else $deltaHp -= 360;
	}
	$deltaLp = $L2 - $L1;
	$deltaCp = $C2p - $C1p;
	$deltaHp = 2 * sqrt($C1p * $C2p) * sin(deg2rad($deltaHp) / 2);

	$S_L = 1 + ((0.015 * pow($barL - 50, 2)) / sqrt(20 + pow($barL - 50, 2)));
	$S_C = 1 + 0.045 * $barCp;
	$S_H = 1 + 0.015 * $barCp * $T;

	$sqrtCp7 = sqrt(pow($barCp, 7) / (pow($barCp, 7) + 6103515625));
	$exp = exp(-(pow(($barHp - 275) / 25, 2)));
	$R_T = -2 * $sqrtCp7 * sin( deg2rad( 60 * $exp ));

	$delta_e_square = pow($deltaLp/$S_L,2) + pow($deltaCp/$S_C,2) + pow($deltaHp/$S_H,2) + $R_T * $deltaCp/$S_C * $deltaHp/$S_H;
	return sqrt( $delta_e_square );
}

$white = array(100.000, 0.005, -0.010);
$yellow = array(97.138, -21.556, 94.482);
$red = array(53.233, 80.109, 67.220);
$black = array(0, 0, 0);

$white_yellow = deltaE_CIE00($white, $yellow);
$yellow_red = deltaE_CIE00($yellow, $red);
$red_black = deltaE_CIE00($red, $black);
xmp_print("white_yellow = [$white_yellow]");
xmp_print("yellow_red = [$yellow_red]");
xmp_print("red_black = [$red_black]");

2 실행 결과[ | ]

white_yellow = [30.53490615714]
yellow_red = [64.307240929461]
red_black = [50.406762679259]

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}