function _smartcrop_gd_entropy in Smart Crop 6
Same name and namespace in other branches
- 7 image.gd.inc \_smartcrop_gd_entropy()
Compute the entropy of an image, defined as -sum(p.*log2(p)).
Parameters
resource $img GD image resource.:
Return value
float The entropy of the image.
2 calls to _smartcrop_gd_entropy()
- SmartcropTestCase::testEntropy in tests/
smartcrop.test - Verify the entropy calculation with a known image.
- _smartcrop_gd_entropy_slice in ./
imageapi_gd.inc - Compute the entropy of an image slice.
File
- ./
imageapi_gd.inc, line 129 - libgd implementation of smartcrop action.
Code
function _smartcrop_gd_entropy($img) {
$histogram = _smartcrop_gd_histogram($img);
$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;
}