Lab-RGB 색상 변환 구현

Lab-RGB 색상 변환 구현
lab2rgb

1 소스 코드[ | ]

<?php
function xmp($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }
function lab2rgb($lab) {
	list($l, $a, $b) = $lab;
	$y = $l/116 + 0.1379310344827586;
	$x = $a/500 + $y;
	$z = $y - $b/200;

	$x = $x > 0.2068965517241379 ? pow($x,3) : $x/7.787 - 0.0177129876053369;
	$y = $y > 0.2068965517241379 ? pow($y,3) : $y/7.787 - 0.0177129876053369;
	$z = $z > 0.2068965517241379 ? pow($z,3) : $z/7.787 - 0.0177129876053369;

	// Observer = 2°, Illuminant = D65
	$r =  3.080093082*$x -1.5372*$y -0.542890638*$z;
	$g = -0.920910383*$x +1.8758*$y +0.045186445*$z;
	$b =  0.052941179*$x -0.2040*$y +1.150893310*$z;

	$r = $r > 0.0031308 ? pow( $r, 0.4166666666666667)*269.025 - 14.025 : $r*3294.6;
	$g = $g > 0.0031308 ? pow( $g, 0.4166666666666667)*269.025 - 14.025 : $g*3294.6;
	$b = $b > 0.0031308 ? pow( $b, 0.4166666666666667)*269.025 - 14.025 : $b*3294.6;
	
	return array(round($r), round($g), round($b));
}

$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);

xmp( lab2rgb( $white ) );
xmp( lab2rgb( $yellow ) );
xmp( lab2rgb( $red ) );
xmp( lab2rgb( $black ) );

2 실행 결과[ | ]

Array
(
    [0] => 255
    [1] => 255
    [2] => 255
)
Array
(
    [0] => 255
    [1] => 255
    [2] => 0
)
Array
(
    [0] => 255
    [1] => 0
    [2] => 0
)
Array
(
    [0] => 0
    [1] => 0
    [2] => 0
)

3 같이 보기[ | ]

4 참고[ | ]

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