JansenFelipe\OMR\Area::percentBlack PHP Method

percentBlack() public method

Percentage of black pixels
public percentBlack ( )
    public function percentBlack()
    {
        return 100 * $this->blackPixels / $this->pixels;
    }

Usage Example

Beispiel #1
0
 /**
  * Returns pixel analysis in a rectangular area
  *
  * @param Point $a
  * @param Point $b
  * @param float $tolerance
  * @return Area
  */
 protected function rectangleArea(Point $a, Point $b, $tolerance)
 {
     $imagick = $this->getImagick();
     $width = $b->getX() - $a->getX();
     $height = $b->getY() - $a->getY();
     $pixels = $imagick->exportImagePixels($a->getX(), $a->getY(), $width, $height, "I", Imagick::PIXEL_CHAR);
     $counts = array_count_values($pixels);
     $blacks = 0;
     $whites = 0;
     foreach ($counts as $k => $qtd) {
         if ($k == -1) {
             $whites += $qtd;
         } else {
             $blacks += $qtd;
         }
     }
     $area = new Area(count($pixels), $whites, $blacks);
     //Add draw debug
     $this->draw->setStrokeOpacity(1);
     $this->draw->setFillOpacity(0);
     $this->draw->setStrokeWidth(2);
     $this->draw->setStrokeColor($area->percentBlack() >= $tolerance ? "#0000CC" : "#CC0000");
     $this->draw->rectangle($a->getX(), $a->getY(), $b->getX(), $b->getY());
     return $area;
 }