XYZ-Lab 색상 변환 구현

XYZ-Lab 색상 변환 구현

1 소스 코드[ | ]

<?php
function xmp_print($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }
function xyz2lab($xyz) {
	list($x, $y, $z) = $xyz;

	// Illuminant = D65, Observer = 2°, 
	$x /= 95.047;
	$y /= 100.00;
	$z /= 108.883;

	// Illuminant = D65, Observer = 10°, 
	//$x /= 94.8110;
	//$y /= 100.00;
	//$z /= 107.304;

	$x = $x > 0.0088564516790356 ? pow($x,0.3333333333333333) : $x*7.787 + 0.1379310344827586;
	$y = $y > 0.0088564516790356 ? pow($y,0.3333333333333333) : $y*7.787 + 0.1379310344827586;
	$z = $z > 0.0088564516790356 ? pow($z,0.3333333333333333) : $z*7.787 + 0.1379310344827586;

	$l = 116*$y - 16;
	$a = 500 * ($x - $y);
	$b = 200 * ($y - $z);
	return array($l, $a, $b);
}

$white = array(95.050, 100.000, 108.900);
$yellow = array(77.000, 92.780, 13.850);
$red = array(41.240, 21.260, 1.930);
$black = array(0, 0, 0);

xmp_print( xyz2lab( $white ) );
xmp_print( xyz2lab( $yellow ) );
xmp_print( xyz2lab( $red ) );
xmp_print( xyz2lab( $black ) );

2 실행 결과[ | ]

Array
(
    [0] => 100
    [1] => 0.0052604999583039
    [2] => -0.010408184525312
)
Array
(
    [0] => 97.138246981297
    [1] => -21.555908334832
    [2] => 94.482485446445
)
Array
(
    [0] => 53.232881785842
    [1] => 80.109309529822
    [2] => 67.220068310264
)
Array
(
    [0] => -3.5527136788005E-15
    [1] => 0
    [2] => 0
)

3 같이 보기[ | ]

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