protected function Face_Detector::compute_ii in Image Focus Crop 7
Same name and namespace in other branches
- 6 php-facedetection/FaceDetector.php \Face_Detector::compute_ii()
1 call to Face_Detector::compute_ii()
- Face_Detector::get_img_stats in php-facedetection/
FaceDetector.php
File
- php-facedetection/
FaceDetector.php, line 107
Class
Code
protected function compute_ii($canvas, $image_width, $image_height) {
$ii_w = $image_width + 1;
$ii_h = $image_height + 1;
$ii = array();
$ii2 = array();
for ($i = 0; $i < $ii_w; $i++) {
$ii[$i] = 0;
$ii2[$i] = 0;
}
for ($i = 1; $i < $ii_h - 1; $i++) {
$ii[$i * $ii_w] = 0;
$ii2[$i * $ii_w] = 0;
$rowsum = 0;
$rowsum2 = 0;
for ($j = 1; $j < $ii_w - 1; $j++) {
$rgb = ImageColorAt($canvas, $j, $i);
$red = $rgb >> 16 & 0xff;
$green = $rgb >> 8 & 0xff;
$blue = $rgb & 0xff;
$grey = 0.2989 * $red + 0.587 * $green + 0.114 * $blue >> 0;
// this is what matlab uses
$rowsum += $grey;
$rowsum2 += $grey * $grey;
$ii_above = ($i - 1) * $ii_w + $j;
$ii_this = $i * $ii_w + $j;
$ii[$ii_this] = $ii[$ii_above] + $rowsum;
$ii2[$ii_this] = $ii2[$ii_above] + $rowsum2;
}
}
return array(
'ii' => $ii,
'ii2' => $ii2,
);
}