RGB-Lab 색상 변환 구현

(PHP rgb2lab에서 넘어옴)
RGB-Lab 색상 변환 구현
rgb2lab

1 소스 코드[ | ]

<?php
function xmp_print($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }
function rgb2lab($rgb){
	// Observer = 2°, Illuminant = D65
	list($r, $g, $b) = $rgb;

	$r = $r > 10.31475 ? pow($r/269.025 + 0.0521327014218009, 2.4)*100 : $r/32.946;
	$g = $g > 10.31475 ? pow($g/269.025 + 0.0521327014218009, 2.4)*100 : $g/32.946;
	$b = $b > 10.31475 ? pow($b/269.025 + 0.0521327014218009, 2.4)*100 : $b/32.946;

	$x = $r*0.0043389060149189 + $g*0.0037623491535767 + $b*0.0018990604648227;
	$y = $r*0.002126 + $g*0.007152 + $b*0.000722;
	$z = $r*0.0001772544841710827 + $g*0.0010947530835851 + $b*0.0087295537411717;

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

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

$white = array(255,255,255);
$yellow = array(255,255,0);
$red = array(255,0,0);
$black = array(0,0,0);

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

2 실행 결과[ | ]

Array
(
    [0] => 100
    [1] => 0.0052604999590811
    [2] => -0.010408184524957
)
Array
(
    [0] => 97.138246981297
    [1] => -21.555908334832
    [2] => 94.482485446445
)
Array
(
    [0] => 53.232881785842
    [1] => 80.109309529821
    [2] => 67.220068310264
)
Array
(
    [0] => 0
    [1] => 0
    [2] => 0
)

3 같이 보기[ | ]

4 참고[ | ]

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