protected function colorEntropy(\Imagick $image)
    {
        $histogram = $image->getImageHistogram();
        $newHistogram = array();

        // Translates a color histogram into a bw histogram
        $colors = count($histogram);
        for ($idx = 0; $idx < $colors; $idx++) {
            $colors = $histogram[$idx]->getColor();
            $grey = $this->rgb2bw($colors['r'], $colors['g'], $colors['b']);
            if (!isset($newHistogram[$grey])) {
                $newHistogram[$grey] = $histogram[$idx]->getColorCount();
            } else {
                $newHistogram[$grey] += $histogram[$idx]->getColorCount();
            }
        }

        return $this->getEntropy($newHistogram, $this->area($image));
    }
protected function colorEntropy(\Imagick $image)
    {
        $histogram = $image->getImageHistogram();
        $newHistogram = array();

        // Translates a color histogram into a bw histogram
        $colors = count($histogram);
        for ($idx = 0; $idx < $colors; $idx++) {
            $colors = $histogram[$idx]->getColor();
            $grey = $this->rgb2bw($colors['r'], $colors['g'], $colors['b']);
            if (!isset($newHistogram[$grey])) {
                $newHistogram[$grey] = $histogram[$idx]->getColorCount();
            } else {
                $newHistogram[$grey] += $histogram[$idx]->getColorCount();
            }
        }

        return $this->getEntropy($newHistogram, $this->area($image));
    }
protected function colorEntropy ( \ Imagick $ image ) { $ histogram = $ image -> getImageHistogram ( ) ; $ newHistogram = array ( ) ; // Translates a color histogram into a bw histogram $ colors = count ( $ histogram ) ; for ( $ idx = 0 ; $ idx < $ colors ; $ idx ++ ) { $ colors = $ histogram [ $ idx ] -> getColor ( ) ; $ grey = $ this -> rgb2bw ( $ colors [ 'r' ] , $ colors [ 'g' ] , $ colors [ 'b' ] ) ; if ( ! isset ( $ newHistogram [ $ grey ] ) ) { $ newHistogram [ $ grey ] = $ histogram [ $ idx ] -> getColorCount ( ) ; } else { $ newHistogram [ $ grey ] += $ histogram [ $ idx ] -> getColorCount ( ) ; } } return $ this -> getEntropy ( $ newHistogram , $ this -> area ( $ image ) ) ; }
Find out the entropy for a color image

If the source image is in color we need to transform RGB into a grayscale image
so we can calculate the entropy more performant.

@param  \Imagick $image
@return float
Find out the entropy for a color image