def test_three_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('three_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath)
        self.assertEqual(3, cg.number_of_nodes())
        self.assertEqual(3, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={'nfeatures':500})
        for i, node, in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        cg.match_features(k=5)

        for source, destination, edge in cg.edges_iter(data=True):
            edge.symmetry_check()
            edge.ratio_check(clean_keys=['symmetry'], ratio=0.99)

        cg.apply_func_to_edges("compute_homography", clean_keys=['symmetry', 'ratio'])
        cg.compute_fundamental_matrices(clean_keys=['symmetry', 'ratio'])

        # Step: And create a C object
        cg.generate_cnet(clean_keys=['symmetry', 'ratio', 'ransac'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, 'TestThreeImageMatching_fromlist.lis')

        # Step: Create a correspondence network
        cg.generate_cnet(clean_keys=['symmetry', 'ratio', 'ransac'], deepen=True)

        to_isis('TestThreeImageMatching.net', cg, mode='wb',
                networkid='TestThreeImageMatching', targetname='Moon')
Esempio n. 2
0
def match_images(args, config_dict):
    # 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=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'),
                         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'),
                         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'],
                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'))
    def test_two_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path("two_image_adjacency.json")
        basepath = get_path("Apollo15")
        cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)
        self.assertEqual(2, cg.number_of_nodes())
        self.assertEqual(1, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(method="sift", extractor_parameters={"nfeatures": 500})
        for i, node in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        # Step: Compute the coverage ratios
        truth_ratios = [0.95351579, 0.93595664]
        for i, node in cg.nodes_iter(data=True):
            ratio = node.coverage_ratio()
            self.assertIn(round(ratio, 8), truth_ratios)

        cg.match_features(k=2)

        # Perform the symmetry check
        cg.symmetry_checks()
        # Perform the ratio check
        cg.ratio_checks(clean_keys=["symmetry"], single=True)
        # Create fundamental matrix
        cg.compute_fundamental_matrices(clean_keys=["symmetry", "ratio"])

        for source, destination, edge in cg.edges_iter(data=True):

            # Perform the symmetry check
            self.assertIn(edge.masks["symmetry"].sum(), range(400, 600))
            # Perform the ratio test
            self.assertIn(edge.masks["ratio"].sum(), range(225, 275))

            # Range needs to be set
            self.assertIn(edge.masks["fundamental"].sum(), range(200, 250))

        # Step: Compute the homographies and apply RANSAC
        cg.compute_homographies(clean_keys=["symmetry", "ratio"])

        # Apply AMNS
        cg.suppress(k=30, suppression_func=error)

        # Step: Compute subpixel offsets for candidate points
        cg.subpixel_register(clean_keys=["suppression"])

        # Step: And create a C object
        cg.generate_cnet(clean_keys=["subpixel"])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, path="fromlis.lis")

        # Step: Output a control network
        to_isis("TestTwoImageMatching.net", cg, mode="wb", networkid="TestTwoImageMatching", targetname="Moon")
Esempio n. 4
0
    def test_two_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('two_image_adjacency.json')
        cg = CandidateGraph.from_adjacency(adjacency)
        self.assertEqual(2, cg.number_of_nodes())
        self.assertEqual(1, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={"nfeatures":500})
        for node, attributes in cg.nodes_iter(data=True):
            self.assertIn(len(attributes['keypoints']), range(490, 511))

        # Step: Then apply a FLANN matcher
        fl = FlannMatcher()
        for node, attributes in cg.nodes_iter(data=True):
            fl.add(attributes['descriptors'], key=node)
        fl.train()

        for node, attributes in cg.nodes_iter(data=True):
            descriptors = attributes['descriptors']
            matches = fl.query(descriptors, node, k=5)
            cg.add_matches(matches)

        for source, destination, attributes in cg.edges_iter(data=True):
            matches = attributes['matches']
            # Perform the symmetry check
            symmetry_mask = od.mirroring_test(matches)
            self.assertIn(symmetry_mask.sum(), range(430, 461))
            attributes['symmetry'] = symmetry_mask

            # Perform the ratio test
            ratio_mask = od.distance_ratio(matches, ratio=0.95)
            self.assertIn(ratio_mask.sum(), range(390, 451))
            attributes['ratio'] = ratio_mask

            mask = np.array(ratio_mask * symmetry_mask)
            self.assertIn(len(matches.loc[mask]), range(75,101))

        # Step: Compute the homographies and apply RANSAC
        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Step: Compute subpixel offsets for candidate points
        cg.compute_subpixel_offsets(clean_keys=['symmetry', 'ratio', 'ransac'])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac', 'subpixel'])
        # Step update the serial numbers
        nid_to_serial = {}
        for node, attributes in cg.nodes_iter(data=True):
            nid_to_serial[node] = self.serial_numbers[attributes['image_name']]

        cnet.replace({'nid': nid_to_serial}, inplace=True)

        # Step: Output a control network
        to_isis('TestTwoImageMatching.net', cnet, mode='wb',
                networkid='TestTwoImageMatching', targetname='Moon')
Esempio n. 5
0
    def test_two_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path("two_image_adjacency.json")
        cg = CandidateGraph.from_adjacency(adjacency)
        self.assertEqual(2, cg.number_of_nodes())
        self.assertEqual(1, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(500)
        for node, attributes in cg.nodes_iter(data=True):
            self.assertIn(len(attributes["keypoints"]), range(490, 511))

        # Step: Then apply a FLANN matcher
        fl = FlannMatcher()
        for node, attributes in cg.nodes_iter(data=True):
            fl.add(attributes["descriptors"], key=node)
        fl.train()

        for node, attributes in cg.nodes_iter(data=True):
            descriptors = attributes["descriptors"]
            matches = fl.query(descriptors, node, k=5)
            cg.add_matches(matches)

        for source, destination, attributes in cg.edges_iter(data=True):
            matches = attributes["matches"]
            # Perform the symmetry check
            symmetry_mask = od.mirroring_test(matches)
            self.assertIn(symmetry_mask.sum(), range(430, 461))
            attributes["symmetry"] = symmetry_mask

            # Perform the ratio test
            ratio_mask = od.distance_ratio(matches, ratio=0.95)
            self.assertIn(ratio_mask.sum(), range(400, 451))
            attributes["ratio"] = ratio_mask

            mask = np.array(ratio_mask * symmetry_mask)
            self.assertIn(len(matches.loc[mask]), range(75, 101))

            cg.compute_homographies(clean_keys=["symmetry", "ratio"])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=["symmetry", "ratio", "ransac"])
        # Step update the serial numbers
        nid_to_serial = {}
        for node, attributes in cg.nodes_iter(data=True):
            nid_to_serial[node] = self.serial_numbers[attributes["image_name"]]

        cnet.replace({"nid": nid_to_serial}, inplace=True)

        # Step: Output a control network
        to_isis("TestTwoImageMatching.net", cnet, mode="wb", networkid="TestTwoImageMatching", targetname="Moon")
Esempio n. 6
0
    def test_three_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('three_image_adjacency.json')
        cg = CandidateGraph.from_adjacency(adjacency)
        self.assertEqual(3, cg.number_of_nodes())
        self.assertEqual(3, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={'nfeatures':500})
        for node, attributes in cg.nodes_iter(data=True):
            self.assertIn(len(attributes['keypoints']), range(490, 511))

        fl = FlannMatcher()
        for node, attributes in cg.nodes_iter(data=True):
            fl.add(attributes['descriptors'], key=node)
        fl.train()

        for node, attributes in cg.nodes_iter(data=True):
            descriptors = attributes['descriptors']
            matches = fl.query(descriptors, node, k=5)
            cg.add_matches(matches)

        for source, destination, attributes in cg.edges_iter(data=True):
            matches = attributes['matches']
            # Perform the symmetry check
            symmetry_mask = od.mirroring_test(matches)
            attributes['symmetry'] = symmetry_mask

            # Perform the ratio test
            ratio_mask = od.distance_ratio(matches, ratio=0.8)
            attributes['ratio'] = ratio_mask

        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac'])

        # Step update the serial numbers
        nid_to_serial = {}
        for node, attributes in cg.nodes_iter(data=True):
            nid_to_serial[node] = self.serial_numbers[attributes['image_name']]

        cnet.replace({'nid': nid_to_serial}, inplace=True)
        # Step: Output a control network
        to_isis('TestThreeImageMatching.net', cnet, mode='wb',
                networkid='TestThreeImageMatching', targetname='Moon')
Esempio n. 7
0
    def test_three_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('three_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath)
        self.assertEqual(3, cg.number_of_nodes())
        self.assertEqual(3, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={'nfeatures': 500})
        for i, node, in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        cg.match_features(k=5)

        for source, destination, edge in cg.edges_iter(data=True):
            matches = edge.matches
            edge.symmetry_check()
            edge.ratio_check(ratio=0.8)

        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, 'TestThreeImageMatching_fromlist.lis')

        # Step update the serial numbers
        nid_to_serial = {}
        for i, node in cg.nodes_iter(data=True):
            nid_to_serial[i] = self.serial_numbers[node.image_name]

        cnet.replace({'nid': nid_to_serial}, inplace=True)
        # Step: Output a control network
        to_isis('TestThreeImageMatching.net',
                cnet,
                mode='wb',
                networkid='TestThreeImageMatching',
                targetname='Moon')
Esempio n. 8
0
    def test_three_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('three_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath)
        self.assertEqual(3, cg.number_of_nodes())
        self.assertEqual(3, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={'nfeatures': 500})
        for i, node, in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        cg.match_features(k=5)

        for source, destination, edge in cg.edges_iter(data=True):
            edge.symmetry_check()
            edge.ratio_check(clean_keys=['symmetry'], ratio=0.99)

        cg.apply_func_to_edges("compute_homography",
                               clean_keys=['symmetry', 'ratio'])
        cg.compute_fundamental_matrices(clean_keys=['symmetry', 'ratio'])

        # Step: And create a C object
        cg.generate_cnet(clean_keys=['symmetry', 'ratio', 'ransac'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, 'TestThreeImageMatching_fromlist.lis')

        # Step: Create a correspondence network
        cg.generate_cnet(clean_keys=['symmetry', 'ratio', 'ransac'],
                         deepen=True)

        to_isis('TestThreeImageMatching.net',
                cg,
                mode='wb',
                networkid='TestThreeImageMatching',
                targetname='Moon')
Esempio n. 9
0
    def test_three_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('three_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath)
        self.assertEqual(3, cg.number_of_nodes())
        self.assertEqual(3, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={'nfeatures':500})
        for i, node, in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        cg.match_features(k=5)

        for source, destination, edge in cg.edges_iter(data=True):
            matches = edge.matches
            edge.symmetry_check()
            edge.ratio_check(ratio=0.8)

        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, 'TestThreeImageMatching_fromlist.lis')

        # Step update the serial numbers
        nid_to_serial = {}
        for i, node in cg.nodes_iter(data=True):
            nid_to_serial[i] = self.serial_numbers[node.image_name]

        cnet.replace({'nid': nid_to_serial}, inplace=True)
        # Step: Output a control network
        to_isis('TestThreeImageMatching.net', cnet, mode='wb',
                networkid='TestThreeImageMatching', targetname='Moon')
Esempio n. 10
0
    def test_three_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path("three_image_adjacency.json")
        basepath = get_path("Apollo15")
        cg = CandidateGraph.from_adjacency(adjacency, basepath)
        self.assertEqual(3, cg.number_of_nodes())
        self.assertEqual(3, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(extractor_parameters={"nfeatures": 500})
        for i, node in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        cg.match_features(k=5)

        for source, destination, edge in cg.edges_iter(data=True):
            edge.symmetry_check()
            edge.ratio_check(clean_keys=["symmetry"], ratio=0.99)

        cg.apply_func_to_edges("compute_homography", clean_keys=["symmetry", "ratio"])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=["symmetry", "ratio", "ransac"])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, "TestThreeImageMatching_fromlist.lis")

        # Step update the serial numbers
        nid_to_serial = {}
        for i, node in cg.nodes_iter(data=True):
            nid_to_serial[i] = self.serial_numbers[node.image_name]

        cnet.replace({"nid": nid_to_serial}, inplace=True)
        # Step: Output a control network
        to_isis("TestThreeImageMatching.net", cnet, mode="wb", networkid="TestThreeImageMatching", targetname="Moon")
Esempio n. 11
0
    def test_two_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('two_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)
        self.assertEqual(2, cg.number_of_nodes())
        self.assertEqual(1, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(method='sift', extractor_parameters={"nfeatures":500})
        for i, node in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        #Step: Compute the coverage ratios
        truth_ratios = [0.95351579,
                        0.93595664]
        for i, node in cg.nodes_iter(data=True):
            ratio = node.coverage_ratio()
            self.assertIn(round(ratio,8), truth_ratios)
        # Step: apply Adaptive non-maximal suppression
        for i, node in cg.nodes_iter(data=True):
            pass
            #node.anms()
            #self.assertNotEqual(node.nkeypoints, sum(node._mask_arrays['anms']))

        cg.match_features(k=5)

        for source, destination, edge in cg.edges_iter(data=True):

            # Perform the symmetry check
            edge.symmetry_check()
            self.assertIn(edge.masks['symmetry'].sum(), range(430, 461))

            # Perform the ratio test
            edge.ratio_check(ratio=0.9, clean_keys=['symmetry'])
            self.assertIn(edge.masks['ratio'].sum(), range(25, 50))

        # Step: Compute the homographies and apply RANSAC
        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Step: Compute the overlap ratio and coverage ratio
        for s, d, edge in cg.edges_iter(data=True):
            ratio = edge.coverage_ratio(clean_keys=['symmetry', 'ratio'])

        # Step: Compute subpixel offsets for candidate points
        cg.subpixel_register(clean_keys=['ransac'])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac', 'subpixel'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, path="fromlis.lis")

        # Step update the serial numbers
        nid_to_serial = {}
        for i, node in cg.nodes_iter(data=True):
            nid_to_serial[i] = self.serial_numbers[node.image_name]

        cnet.replace({'nid': nid_to_serial}, inplace=True)
        # Step: Output a control network
        to_isis('TestTwoImageMatching.net', cnet, mode='wb',
                networkid='TestTwoImageMatching', targetname='Moon')
Esempio n. 12
0
    def test_two_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('two_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)
        self.assertEqual(2, cg.number_of_nodes())
        self.assertEqual(1, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(method='sift',
                            extractor_parameters={"nfeatures": 500})
        for i, node in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        # Step: Compute the coverage ratios
        truth_ratios = [0.95351579, 0.93595664]
        for i, node in cg.nodes_iter(data=True):
            ratio = node.coverage_ratio()
            self.assertIn(round(ratio, 8), truth_ratios)

        cg.match_features(k=2)

        # Perform the symmetry check
        cg.symmetry_checks()
        # Perform the ratio check
        cg.ratio_checks(clean_keys=['symmetry'], single=True)
        # Create fundamental matrix
        cg.compute_fundamental_matrices(clean_keys=['symmetry', 'ratio'])

        for source, destination, edge in cg.edges_iter(data=True):

            # Perform the symmetry check
            self.assertIn(edge.masks['symmetry'].sum(), range(400, 600))
            # Perform the ratio test
            self.assertIn(edge.masks['ratio'].sum(), range(225, 275))

            # Range needs to be set
            self.assertIn(edge.masks['fundamental'].sum(), range(200, 250))

        # Step: Compute the homographies and apply RANSAC
        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Apply AMNS
        cg.suppress(k=30, suppression_func=error)

        # Step: Compute subpixel offsets for candidate points
        cg.subpixel_register(clean_keys=['suppression'])

        # Step: And create a C object
        cg.generate_cnet(clean_keys=['subpixel'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, path="fromlis.lis")

        # Step: Output a control network
        to_isis('TestTwoImageMatching.net',
                cg,
                mode='wb',
                networkid='TestTwoImageMatching',
                targetname='Moon')
Esempio n. 13
0
    def test_two_image(self):
        # Step: Create an adjacency graph
        adjacency = get_path('two_image_adjacency.json')
        basepath = get_path('Apollo15')
        cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)
        self.assertEqual(2, cg.number_of_nodes())
        self.assertEqual(1, cg.number_of_edges())

        # Step: Extract image data and attribute nodes
        cg.extract_features(method='sift', extractor_parameters={"nfeatures":500})
        for i, node in cg.nodes_iter(data=True):
            self.assertIn(node.nkeypoints, range(490, 511))

        #Step: Compute the coverage ratios
        truth_ratios = [0.95351579,
                        0.93595664]
        for i, node in cg.nodes_iter(data=True):
            ratio = node.coverage_ratio()
            self.assertIn(round(ratio,8), truth_ratios)
        # Step: apply Adaptive non-maximal suppression
        for i, node in cg.nodes_iter(data=True):
            pass
            #node.anms()
            #self.assertNotEqual(node.nkeypoints, sum(node._mask_arrays['anms']))

        cg.match_features(k=5)

        for source, destination, edge in cg.edges_iter(data=True):

            # Perform the symmetry check
            edge.symmetry_check()
            self.assertIn(edge._mask_arrays['symmetry'].sum(), range(430, 461))

            # Perform the ratio test
            edge.ratio_check(ratio=0.8)
            self.assertIn(edge._mask_arrays['ratio'].sum(), range(250, 350))

        # Step: Compute the homographies and apply RANSAC
        cg.compute_homographies(clean_keys=['symmetry', 'ratio'])

        # Step: Compute the overlap ratio and coverage ratio
        for s, d, edge in cg.edges_iter(data=True):
            ratio = edge.coverage_ratio(clean_keys=['symmetry', 'ratio'])

        # Step: Compute subpixel offsets for candidate points
        cg.compute_subpixel_offsets(clean_keys=['ransac'])

        # Step: And create a C object
        cnet = cg.to_cnet(clean_keys=['symmetry', 'ratio', 'ransac', 'subpixel'])

        # Step: Create a fromlist to go with the cnet and write it to a file
        filelist = cg.to_filelist()
        write_filelist(filelist, path="fromlis.lis")

        # Step update the serial numbers
        nid_to_serial = {}
        for i, node in cg.nodes_iter(data=True):
            nid_to_serial[i] = self.serial_numbers[node.image_name]

        cnet.replace({'nid': nid_to_serial}, inplace=True)
        # Step: Output a control network
        to_isis('TestTwoImageMatching.net', cnet, mode='wb',
                networkid='TestTwoImageMatching', targetname='Moon')
Esempio n. 14
0
def match_images(args, config_dict):
    # 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=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'),
        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'),
        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'],
                           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'))