def build_multipuzzle_solver(image_filenames, puzzle_type, piece_width):
    """
    Build the multipuzzle solver object.

    Args:
        image_filenames (List[str]): List of puzzle file paths.
        puzzle_type (PuzzleType): Type of the puzzle to solve.
        piece_width (int): Puzzle piece width in number of pixels

    Returns (MultiPuzzleSolver): The multipuzzle solver object built from the input image files.
    """

    pieces, puzzles = Puzzle.get_combined_pieces_multiple_images(image_filenames, piece_width)

    pickle_filename = PickleHelper.build_filename("multipuzzle_distances", image_filenames, puzzle_type)

    # Initialize the distance information
    if _FORCE_RECALCULATE_DISTANCES or not os.path.exists(pickle_filename):
        multipuzzle_solver = MultiPuzzleSolver(image_filenames, pieces, top_level_calculate_asymmetric_distance,
                                               puzzle_type)

        if _POST_INITIAL_CONSTRUCTION_PICKLE_EXPORT:
            PickleHelper.exporter(multipuzzle_solver, pickle_filename)
        return multipuzzle_solver

    # Read the pickle information from the
    else:
        multipuzzle_solver = PickleHelper.importer(pickle_filename)
        multipuzzle_solver.reset_timestamp()
        return multipuzzle_solver
Exemple #2
0
    def run_imported_stitching_piece_solving(image_filenames, puzzle_type):
        """
        Debug method that is used to test the stitching piece solving.

        Args:
            image_filenames (List[str]): List of paths to image file names
            puzzle_type (PuzzleType): Solver puzzle type
        """
        pickle_filename = PickleHelper.build_filename(MultiPuzzleSolver._POST_SEGMENTATION_COMPLETED_PICKLE_FILE_DESCRIPTOR,
                                                      image_filenames, puzzle_type)
        solver = PickleHelper.importer(pickle_filename)
        # noinspection PyProtectedMember
        solver.reset_timestamp()

        # noinspection PyProtectedMember
        solver._perform_stitching_piece_solving()
Exemple #3
0
    def run_imported_similarity_matrix_calculation(image_filenames, puzzle_type):
        """
        Debug method that imports a pickle file for the specified image files, puzzle type, and segmentation round
        and then runs the initial segmentation starting after the specified round.

        Args:
            image_filenames (List[str]): List of paths to image file names
            puzzle_type (PuzzleType): Solver puzzle type
        """
        pickle_file_descriptor = MultiPuzzleSolver._POST_STITCHING_PIECE_SOLVING_PICKLE_FILE_DESCRIPTOR
        pickle_filename = PickleHelper.build_filename(pickle_file_descriptor, image_filenames, puzzle_type)

        solver = PickleHelper.importer(pickle_filename)
        # noinspection PyProtectedMember
        solver.reset_timestamp()

        # noinspection PyProtectedMember
        solver._build_similarity_matrix()
Exemple #4
0
    def run_imported_select_starting_pieces(image_filenames, puzzle_type):
        """
        Debug method that imports a pickle file after hierarchical clustering was completed.  It then selects the
        seed pieces as inputs to the solver..

        Note: The pickle file name is built from the image file names and the puzzle type.

        Args:
            image_filenames (List[str]): List of paths to image file names
            puzzle_type (PuzzleType): Solver puzzle type
        """
        pickle_file_descriptor = MultiPuzzleSolver._POST_HIERARCHICAL_CLUSTERING_PICKLE_FILE_DESCRIPTOR
        pickle_filename = PickleHelper.build_filename(pickle_file_descriptor, image_filenames, puzzle_type)

        solver = PickleHelper.importer(pickle_filename)
        solver.reset_timestamp()

        # noinspection PyProtectedMember
        solver._select_starting_pieces_from_clusters()
Exemple #5
0
    def run_imported_hierarchical_clustering(image_filenames, puzzle_type):
        """
        Debug method that imports a pickle file after the similarity matrix was built.  It then runs hierarchical
        clustering on that imported pickle file.

        Note: The pickle file name is built from the image file names and the puzzle type.

        Args:
            image_filenames (List[str]): List of paths to image file names
            puzzle_type (PuzzleType): Solver puzzle type
        """
        pickle_file_descriptor = MultiPuzzleSolver._POST_SIMILARITY_MATRIX_CALCULATION_PICKLE_FILE_DESCRIPTOR
        pickle_filename = PickleHelper.build_filename(pickle_file_descriptor, image_filenames, puzzle_type)

        solver = PickleHelper.importer(pickle_filename)
        solver.reset_timestamp()

        # noinspection PyProtectedMember
        solver._perform_hierarchical_clustering()
Exemple #6
0
    def run_imported_segmentation_experiment(image_filenames, puzzle_type, segmentation_round_numb):
        """
        Debug method that imports a pickle file for the specified image files, puzzle type, and segmentation round
        and then runs the initial segmentation starting after the specified round.

        Args:
            image_filenames (List[str]): List of paths to image file names
            puzzle_type (PuzzleType): Solver puzzle type
            segmentation_round_numb (int): Segmentation round number
        """

        file_descriptor = MultiPuzzleSolver._POST_SEGMENTATION_PUZZLE_PLACEMENT_FILE_DESCRIPTOR % segmentation_round_numb
        pickle_filename = PickleHelper.build_filename(file_descriptor, image_filenames, puzzle_type)

        solver = PickleHelper.importer(pickle_filename)
        # noinspection PyProtectedMember
        solver.reset_timestamp()

        # noinspection PyProtectedMember
        solver._find_initial_segments(go_directly_to_segmentation=True)
Exemple #7
0
    def run_imported_segmentation_round(image_filenames, puzzle_type, segmentation_round_numb):
        """
        Debug method that imports a pickle file for the specified image files, puzzle type, and segmentation round
        and then runs the initial segmentation starting after the specified round.

        Args:
            image_filenames (List[str]): List of paths to image file names
            puzzle_type (PuzzleType): Solver puzzle type
            segmentation_round_numb (int): Segmentation round number
        """

        pickle_file_descriptor = "segment_round_%d" % segmentation_round_numb
        pickle_filename = PickleHelper.build_filename(pickle_file_descriptor, image_filenames, puzzle_type)

        solver = PickleHelper.importer(pickle_filename)
        # noinspection PyProtectedMember
        solver.reset_timestamp()

        # noinspection PyProtectedMember
        solver._find_initial_segments(skip_initialization=True)
Exemple #8
0
    def run_imported_final_puzzle_solving(image_filenames, puzzle_type):
        """
        Debug method that imports a pickle file after hierarchical clustering was completed.  It then selects the
        seed pieces as inputs to the solver..

        Note: The pickle file name is built from the image file names and the puzzle type.

        Args:
            image_filenames (List[str]): List of paths to image file names
            puzzle_type (PuzzleType): Solver puzzle type
        """
        pickle_file_descriptor = MultiPuzzleSolver._POST_SELECT_STARTING_PIECES_PICKLE_FILE_DESCRIPTOR
        pickle_filename = PickleHelper.build_filename(pickle_file_descriptor, image_filenames, puzzle_type)

        solver = PickleHelper.importer(pickle_filename)
        solver.reset_timestamp()

        # noinspection PyProtectedMember
        solver._perform_placement_with_final_seed_pieces()
        # noinspection PyProtectedMember
        solver._final_puzzles = solver._build_output_puzzles()
def run_best_buddies_analyzer(image_file, piece_width, puzzle_type):
    """
    Runs the Best Buddy Analyzer on an image and outputs the best buddy results and generates a results image.

    Args:
        image_file (str): Path to an image file
        piece_width (int): Width of a puzzle piece in number of pixels
        puzzle_type (PuzzleType): Type of the puzzle to solve

    """
    pickle_file = PickleHelper.build_filename("bb_accuracy", [image_file], puzzle_type)

    filename_with_image_folder = config.add_image_folder_path([image_file])
    bb_results = ImageBestBuddyStatistics(filename_with_image_folder[0], piece_width, puzzle_type,
                                          top_level_calculate_asymmetric_distance)

    PickleHelper.exporter(bb_results, pickle_file)

    # Calculate the print the results.
    bb_results = PickleHelper.importer(pickle_file)
    bb_results.calculate_results()
    bb_results.print_results()