Commit 4c30ea63 authored by jlaura's avatar jlaura
Browse files

Merge pull request #87 from Kelvinrr/subgraph_from_matches

Create sub-graph from matched images
parents fd63f857 2e411286
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