-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to make nx Graph from Skeleton (#224)
Further to initial work by @jni to implement NetworkX based pruning I've finally worked out how to reconstruct `Skeleton` from the NetworkX graph by storing the `path_coordinates()` in the `edge properties`. We save the `.path_coordinates()` to the edge properties of a NetworkX graph, using the `row.Index` _and_ the `node_id_src` / `node_id_dst` to define the nodes. This is required because in some of the test instances there are loops with the same `src` and `dst` and if only these are used we would lose information. Early work I was recreating the `summarize()` Pandas dataframes and the number of rows were differing which made me scratch my head until I realised the information was being over-written because the `src` and `dst` were the same. Including the `row.Index` as a proxy for the graph segment avoids this. As the `.path_coordinates()` are saved as `edge` properties in NetworkX object we can now reconstruct the original Numpy array based on this information and convert to a `Skeleton`. Tests are included for a range of sample graphs and exceptions are raised (and tested) when... + Wrong type of object is passed into `nx_to_skeleton()`. + The NetworkX object is missing `edge` properties completely. + The `edge` properties are co-ordinates outside of the original images dimensions. There may be more edge cases that we could/should test for. I found problems in reconstructing `tinyline` as it was a 1-D "image" and so have made this a 2-D "image" with a single row and updated `test_line()` appropriately. This may be inappropriate as the intention is to have a 1-D skeleton but most skeletons will be 2-D, can be reverted if necessary. Also on reviewing this still includes WIP on iterative pruning. It desirable this could be removed to keep the PR more focused on going from and to NetworkX graph objects. --------- Co-authored-by: Juan Nunez-Iglesias <[email protected]>
- Loading branch information
Showing
5 changed files
with
444 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.