Esempio n. 1
0
 /**
  * Calculates the mask penalty for a matrix.
  *
  * @param  ByteMatrix $matrix
  * @return integer
  */
 protected static function calculateMaskPenalty(ByteMatrix $matrix)
 {
     return MaskUtil::applyMaskPenaltyRule1($matrix) + MaskUtil::applyMaskPenaltyRule2($matrix) + MaskUtil::applyMaskPenaltyRule3($matrix) + MaskUtil::applyMaskPenaltyRule4($matrix);
 }
Esempio n. 2
0
 public function testApplyMaskPenalty3()
 {
     // Horizontal 00001011101
     $matrix = new ByteMatrix(11, 1);
     $matrix->set(0, 0, 0);
     $matrix->set(1, 0, 0);
     $matrix->set(2, 0, 0);
     $matrix->set(3, 0, 0);
     $matrix->set(4, 0, 1);
     $matrix->set(5, 0, 0);
     $matrix->set(6, 0, 1);
     $matrix->set(7, 0, 1);
     $matrix->set(8, 0, 1);
     $matrix->set(9, 0, 0);
     $matrix->set(10, 0, 1);
     $this->assertEquals(40, MaskUtil::applyMaskPenaltyRule3($matrix));
     // Horizontal 10111010000
     $matrix = new ByteMatrix(11, 1);
     $matrix->set(0, 0, 1);
     $matrix->set(1, 0, 0);
     $matrix->set(2, 0, 1);
     $matrix->set(3, 0, 1);
     $matrix->set(4, 0, 1);
     $matrix->set(5, 0, 0);
     $matrix->set(6, 0, 1);
     $matrix->set(7, 0, 0);
     $matrix->set(8, 0, 0);
     $matrix->set(9, 0, 0);
     $matrix->set(10, 0, 0);
     $this->assertEquals(40, MaskUtil::applyMaskPenaltyRule3($matrix));
     // Vertical 00001011101
     $matrix = new ByteMatrix(1, 11);
     $matrix->set(0, 0, 0);
     $matrix->set(0, 1, 0);
     $matrix->set(0, 2, 0);
     $matrix->set(0, 3, 0);
     $matrix->set(0, 4, 1);
     $matrix->set(0, 5, 0);
     $matrix->set(0, 6, 1);
     $matrix->set(0, 7, 1);
     $matrix->set(0, 8, 1);
     $matrix->set(0, 9, 0);
     $matrix->set(0, 10, 1);
     $this->assertEquals(40, MaskUtil::applyMaskPenaltyRule3($matrix));
     // Vertical 10111010000
     $matrix = new ByteMatrix(1, 11);
     $matrix->set(0, 0, 1);
     $matrix->set(0, 1, 0);
     $matrix->set(0, 2, 1);
     $matrix->set(0, 3, 1);
     $matrix->set(0, 4, 1);
     $matrix->set(0, 5, 0);
     $matrix->set(0, 6, 1);
     $matrix->set(0, 7, 0);
     $matrix->set(0, 8, 0);
     $matrix->set(0, 9, 0);
     $matrix->set(0, 10, 0);
     $this->assertEquals(40, MaskUtil::applyMaskPenaltyRule3($matrix));
 }