protected function ImageFocusEntropy::calculateEntropy in Image Focus Crop 8
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 src/
lib/ ImageFocusEntropy.php - Calculates the focal point.
File
- src/
lib/ ImageFocusEntropy.php, line 72
Class
- ImageFocusEntropy
- Class ImageFocusEntropy.
Namespace
Drupal\image_focus\libCode
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;
}