grains.cad.skeleton2regions¶
-
grains.cad.skeleton2regions(skeleton_network, neighbor_search_algorithm)[source]¶ Determines the regions bounded by a skeleton network.
This function can be perceived as an intermediate step between a skeleton network and completely geometrical representation of the regions. That is, it keeps the key topological information required to create a fully geometrical description, but it also contains the coordinates of the region boundaries. The outputs of this function can be used to build different region representations.
- Parameters
skeleton_network (Skeleton) – Geometrical and topological information about the skeleton network of a label image.
neighbor_search_algorithm (functools.partial) – Specifies which algorithm to use for constructing the branch-region connectivity. The function to be passed (along with its arguments) is
search_neighbor(). For further details, see the Notes below.
- Returns
region_branches (dict) – For each region it contains the branch indices that bound that region.
branch_coordinates (list) – Coordinates of the points on each branch.
branch_regions (dict) – For each branch it contains the neighboring regions. This auxiliary data is not essential as it can be restored from
region_branches. However, it is computed as temporary data needed forregion_branches.
See also
Notes
Although the algorithms were created to require minimum user intervention, some parameters must be fine-tuned so as to achieve an optimal result in identifying the regions. Visualization plays an important role in it. Full automation is either not possible or would require a huge computational cost. The shortcoming of the algorithms in this function is the following. The recognition of which branches form a region is based on the premise that a node of a branch belongs to a region if its n-pixel neighbourhood contains a pixel from that region. Ideally, n=1 would be used, meaning that the single-pixel width skeleton is located at most 1 pixel afar from the regions it lies among. This is true but the nodes of the skeleton can be farther than 1 pixel from a region. Hence, n has to be a parameter of our model. Increasing n helps in identifying the connecting regions to a node of a branch. On the other hand, if n is too large, regions that “in reality” are not neighbors of a branch will be included. Currently, we recommend trying different parameters n, plot the reconstructed regions over the label image using the
overlay_regions()function, and see how good the result is. As a heuristic, start with n=2.