Commit 5027f7ff authored by Kelvin Rodriguez's avatar Kelvin Rodriguez
Browse files

Merge pull request #106 from acpaquette/sugar

Added syntactic sugar to network.py
parents 0e1240b8 8ce54433
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -395,6 +395,63 @@ class CandidateGraph(nx.Graph):
            else:
                func(*args, **kwargs)

    def symmetry_checks(self):
        '''
        Apply a symmetry check to all edges in the graph
        '''
        self.apply_func_to_edges('symmetry_check')

    def ratio_checks(self, *args, **kwargs):
        '''
        Apply a ratio check to all edges in the graph

        See Also
        --------
        autocnet.matcher.outlier_detector.DistanceRatio.compute
        '''
        self.apply_func_to_edges('ratio_check', *args, **kwargs)

    def compute_homographies(self, *args, **kwargs):
        '''
        Compute homographies for all edges using identical parameters

        See Also
        --------
        autocnet.graph.edge.Edge.compute_homography
        autocnet.matcher.outlier_detector.compute_homography
        '''
        self.apply_func_to_edges('compute_homography', *args, **kwargs)

    def compute_fundamental_matrices(self, *args, **kwargs):
        '''
        Compute fundmental matrices for all edges using identical parameters

        See Also
        --------
        autocnet.matcher.outlier_detector.compute_fundamental_matrix
        '''
        self.apply_func_to_edges('compute_fundamental_matrix', *args, **kwargs)

    def subpixel_register(self, *args, **kwargs):
        '''
        Compute subpixel offsets for all edges using identical parameters

        See Also
        --------
        autocnet.graph.edge.Edge.subpixel_register
        '''
        self.apply_func_to_edges('subpixel_register', *args, **kwargs)

    def suppress(self, *args, **kwargs):
        '''
        Apply a metric of point suppression to the graph

        See Also
        --------
        autocnet.matcher.outlier_detector.SpatialSuppression
        '''
        self.apply_func_to_edges('suppress', *args, **kwargs)

    def minimum_spanning_tree(self):
        """
        Calculates the minimum spanning tree of the graph
+17 −5
Original line number Diff line number Diff line
@@ -62,25 +62,37 @@ class TestTwoImageMatching(unittest.TestCase):

        cg.match_features(k=2)

        # Perform the symmetry check
        cg.symmetry_checks()
        # Perform the ratio check
        cg.ratio_checks(clean_keys = ['symmetry'])
        # 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
            edge.symmetry_check()
            self.assertIn(edge.masks['symmetry'].sum(), range(400, 600))

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

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


        # Step: Compute the homographies and apply RANSAC
        cg.apply_func_to_edges("compute_homography", clean_keys=['symmetry', 'ratio'])
        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):
            edge.coverage_ratio(clean_keys=['symmetry', 'ratio'])

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

        # Step:
        cg.suppress()

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