Commit c3fdf9f1 authored by jlaura's avatar jlaura
Browse files

Merge pull request #37 from kree/disconnected_graph

Find disconnected graph components (JIRA #31) (Merge after PR #35)
parents 3850b950 4a17f8df
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -504,4 +504,26 @@ class CandidateGraph(nx.Graph):
            adjacency_dict[n] = self.neighbors(n)
        io_json.write_json(adjacency_dict, outputfile)

    # This could easily be changed to return the image name instead of the node if desired
    def island_nodes(self):
        """
        Finds single nodes that are completely disconnected from the rest of the graph

        Returns
        -------
        : list
          A list of disconnected nodes, nodes of degree zero, island nodes, etc.
        """
        return nx.isolates(self)

    # This could also easily be changed to return image names
    def connected_subgraphs(self):
        """
        Finds and returns a list of each connected subgraph of nodes. Each subgraph is a set.

        Returns
        -------
       : list
          A list of connected sub-graphs of nodes, with the largest sub-graph first. Each subgraph is a set.
        """
        return sorted(nx.connected_components(self), key=len, reverse=True)
+9 −0
Original line number Diff line number Diff line
@@ -46,5 +46,14 @@ class TestCandidateGraph(unittest.TestCase):
        self.assertIsInstance(node['descriptors'][0], np.ndarray)
        self.assertEquals(self.graph.get_keypoints(node_number), node['keypoints'])

    def test_island_nodes(self):
        self.assertEqual(len(self.graph.island_nodes()), 1)

    def test_connected_subgraphs(self):
        subgraph_list = self.graph.connected_subgraphs()
        self.assertEqual(len(subgraph_list), 2)
        island = self.graph.island_nodes()[0]
        self.assertTrue(island in subgraph_list[1])

    def tearDown(self):
        pass
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ class TestTwoImageMatching(unittest.TestCase):
            attributes['ratio'] = ratio_mask

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

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