You are here

protected function ImageFocusEntropy::calculateEntropy in Image Focus Crop 6

Same name and namespace in other branches
  1. 7 image_focus.entropy.inc \ImageFocusEntropy::calculateEntropy()

Calculates the entropy of an image zone, defined as -sum(p.*log2(p)) where p is the histogram counts of a grayscale image.

1 call to ImageFocusEntropy::calculateEntropy()
ImageFocusEntropy::calculateFocalPoint in ./image_focus.entropy.inc
Calculates the focal point.

File

./image_focus.entropy.inc, line 48
Image entropy calculation.

Class

ImageFocusEntropy
@file Image entropy calculation.

Code

protected function calculateEntropy($x, $y, $dx, $dy) {
  $histogram = $this
    ->calculateHistogram($x, $y, $dx, $dy);
  $histogram_size = array_sum($histogram);
  $entropy = 0;
  foreach ($histogram as $p) {
    if ($p == 0) {
      continue;
    }
    $p = $p / $histogram_size;
    $entropy += $p * log($p, 2);
  }
  return $entropy * -1;
}