diff --git a/Image/Thresholding.php b/Image/Thresholding.php new file mode 100644 index 000000000..67f1362a2 --- /dev/null +++ b/Image/Thresholding.php @@ -0,0 +1,123 @@ +> 16) & 0xFF; + $sG = ($rgb >> 8) & 0xFF; + $sB = $rgb & 0xFF; + + $vR = $sR / 255; + $vG = $sG / 255; + $vB = $sB / 255; + + $lR = $vR <= 0.04045 ? $vR / 12.92 : \pow((($vR + 0.055) / 1.055), 2.4); + $lG = $vG <= 0.04045 ? $vG / 12.92 : \pow((($vG + 0.055) / 1.055), 2.4); + $lB = $vB <= 0.04045 ? $vB / 12.92 : \pow((($vB + 0.055) / 1.055), 2.4); + + $y = 0.2126 * $lR + 0.7152 * $lG + 0.0722 * $lB; + $lStar = $y <= 216 / 24389 ? $y * 24389 / 27 : \pow($y,(1 / 3)) * 116 - 16; + + return $lStar / 100; + } +} diff --git a/tests/Image/ThresholdingTest.php b/tests/Image/ThresholdingTest.php new file mode 100644 index 000000000..58d68e3fa --- /dev/null +++ b/tests/Image/ThresholdingTest.php @@ -0,0 +1,35 @@ +