public static int applyMaskPenaltyRule2(ByteMatrix matrix) {
    int penalty = 0;
    byte[][] array = matrix.getArray();
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    for (int y = 0; y < height - 1; ++y) {
      for (int x = 0; x < width - 1; ++x) {
        int value = array[y][x];
        if (value == array[y][x + 1] && value == array[y + 1][x] && value == array[y + 1][x + 1]) {
          penalty += 3;
        }
      }
    }
    return penalty;
  }