Commit 3f41be77 authored by Adam Paquette's avatar Adam Paquette
Browse files

Merged with master and finished fix in image_match

parent 4823ca1b
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -698,3 +698,21 @@ class CandidateGraph(nx.Graph):

        H.graph = self.graph
        return H

    def subgraph_from_matches(self):
        """
        Returns a sub-graph where all edges have matches.
        (i.e. images with no matches are removed)

        Returns
        -------
        : Object
          A networkX graph object
        """

        # get all edges that have matches
        matches = [(u, v) for u, v, edge in self.edges_iter(data=True)
                   if hasattr(edge, 'matches') and
                   not edge.matches.empty]

        return self.create_edge_subgraph(matches)
+9 −0
Original line number Diff line number Diff line
@@ -114,6 +114,15 @@ class TestCandidateGraph(unittest.TestCase):
        node_sub = g.create_node_subgraph([0,1])
        self.assertEqual(len(node_sub), 2)

    def test_subgraph_from_matches(self):
        test_sub_graph = self.graph.create_node_subgraph([0, 1])
        test_sub_graph.extract_features(extractor_parameters={'nfeatures': 500})
        test_sub_graph.match_features(k=2)

        sub_graph_from_matches = self.graph.subgraph_from_matches()

        self.assertEqual(test_sub_graph.edges(), sub_graph_from_matches.edges())

    def tearDown(self):
        pass

+9 −57
Original line number Diff line number Diff line
@@ -20,63 +20,9 @@ def parse_arguments():
    return args

def match_images(args, config_dict):
    print(find_in_dict(config_dict, 'ratio'))
    # Matches the images in the input file using various candidate graph methods
    # produces two files usable in isis

    try:
        cg = CandidateGraph.from_adjacency(find_in_dict(config_dict, 'inputfile_path') +
                                           args.input_file, basepath=find_in_dict(config_dict, 'basepath'))
    except:
        cg = CandidateGraph.from_filelist(find_in_dict(config_dict, 'inputfile_path') + args.input_file)

    # Apply SIFT to extract features
    cg.extract_features(method=config_dict['extract_features']['method'],
                        extractor_parameters=find_in_dict(config_dict, 'extractor_parameters'))

    # Match
    cg.match_features(k=config_dict['match_features']['k'])

    # Apply outlier detection
    cg.apply_func_to_edges('symmetry_check')
    cg.apply_func_to_edges('ratio_check',
                    ratio=find_in_dict(config_dict, 'ratio'),
                    mask_name=find_in_dict(config_dict, 'mask_name'),
                    single=find_in_dict(config_dict, 'single'))

    # Compute a homography and apply RANSAC
    cg.apply_func_to_edges('compute_fundamental_matrix', clean_keys=find_in_dict(config_dict, 'fundamental_matrices')['clean_keys'],
                                    method=find_in_dict(config_dict, 'fundamental_matrices')['method'],
                                    reproj_threshold=find_in_dict(config_dict, 'reproj_threshold'),
                                    confidence=find_in_dict(config_dict, 'confidence'))

    cg.apply_func_to_edges('subpixel_register', clean_keys=['fundamental', 'symmetry', 'ratio'], template_size=5, search_size=15)

    cg.apply_func_to_edges('suppress', clean_keys=find_in_dict(config_dict, 'suppress')['clean_keys'],
                k=find_in_dict(config_dict, 'suppress')['k'],
                min_radius=find_in_dict(config_dict, 'min_radius'),
                error_k=find_in_dict(config_dict, 'error_k'))

    cnet = cg.to_cnet(clean_keys=find_in_dict(config_dict, 'cnet_conversion')['clean_keys'],
                      isis_serials=True)

    filelist = cg.to_filelist()

    write_filelist(filelist, find_in_dict(config_dict, 'outputfile_path') + args.output_file + '.lis')

    to_isis(find_in_dict(config_dict, 'outputfile_path') + args.output_file + '.net', cnet,
            mode='wb',
            networkid=find_in_dict(config_dict, 'networkid'),
            targetname=find_in_dict(config_dict, 'targetname'),
            description=find_in_dict(config_dict, 'description'),
            username=find_in_dict(config_dict, 'username'))

if __name__ == '__main__':
    config = read_yaml('image_match_config.yml')
    command_line_args = parse_arguments()
    match_images(command_line_args, config)

'''
    try:
        cg = CandidateGraph.from_adjacency(find_in_dict(config_dict, 'inputfile_path') +
                                           args.input_file, basepath=find_in_dict(config_dict, 'basepath'))
@@ -105,11 +51,13 @@ try:

    cg.apply_func_to_edges('subpixel_register', clean_keys=find_in_dict(config_dict, 'subpixel_register')['clean_keys'],
                         template_size=find_in_dict(config_dict, 'template_size'),
                         threshold=find_in_dict(config_dict, 'threshold_size'),
                         threshold=find_in_dict(config_dict, 'threshold'),
                         search_size=find_in_dict(config_dict, 'search_size'),
                         max_x_shift=find_in_dict(config_dict, 'max_x_shift'),
                         max_y_shift=find_in_dict(config_dict, 'max_y_shift'),
                         tiled=find_in_dict(config_dict, 'tiled'))
                         tiled=find_in_dict(config_dict, 'tiled'),
                         upsampling = find_in_dict(config_dict, 'upsampling'),
                         error_check = find_in_dict(config_dict, 'error_check'))

    cg.apply_func_to_edges('suppress', clean_keys=find_in_dict(config_dict, 'suppress')['clean_keys'],
                k=find_in_dict(config_dict, 'suppress')['k'],
@@ -129,4 +77,8 @@ try:
            targetname=find_in_dict(config_dict, 'targetname'),
            description=find_in_dict(config_dict, 'description'),
            username=find_in_dict(config_dict, 'username'))
'''

if __name__ == '__main__':
    config = read_yaml('image_match_config.yml')
    command_line_args = parse_arguments()
    match_images(command_line_args, config)
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -47,8 +47,9 @@ subpixel_register:
    tiled: False

# Keyword arguments
    upsampling:
    upsampling: 16
    error_check: False
    subpixel_func: cv2.TM_CCOEFF_NORMED

suppress:
    clean_keys: