Grafika\Gd\Editor::_entropy PHP Method

_entropy() private method

Calculate entropy based on histogram.
private _entropy ( $hist ) : float | integer
$hist
return float | integer
    private function _entropy($hist)
    {
        $entropy = 0;
        $hist_size = array_sum($hist['r']) + array_sum($hist['g']) + array_sum($hist['b']);
        foreach ($hist['r'] as $p) {
            $p = $p / $hist_size;
            $entropy += $p * log($p, 2);
        }
        foreach ($hist['g'] as $p) {
            $p = $p / $hist_size;
            $entropy += $p * log($p, 2);
        }
        foreach ($hist['b'] as $p) {
            $p = $p / $hist_size;
            $entropy += $p * log($p, 2);
        }
        return $entropy * -1;
    }