Graphs#
- napari_toska.create_adjacency_matrix(parsed_skeletons: napari.types.LabelsData, neighborhood: str = 'n8') ndarray[source]#
Create an adjacency matrix for a given skeleton image.
Parameters:#
- parsed_skeletons: napari.types.LabelsData
A skeleton image where each pixel is labelled according to the point type which can be either a terminal point (1), a branching point (3), or a chain point (2).
- neighborhood: str
The neighborhood connectivity of the skeleton. Can be “n4”, “n6”, “n8”, “n18”, or “n26”.
Returns:#
- M: np.ndarray
An adjacency matrix for the skeleton.
- napari_toska.create_all_adjancency_matrices(labeled_skeletons: napari.types.LabelsData, parsed_skeletons: napari.types.LabelsData, neighborhood: str)[source]#
Calculate all adjacency matrices for a given skeleton image.
Parameters:#
- labeled_skeletons: napari.types.LabelsData
A skeleton image with each skeleton carrying a unique label.
- parsed_skeletons: napari.types.LabelsData
A skeleton image where each pixel is labelled according to the point type which can be either a terminal point (1), a branching point (3), or a chain point (2).
- neighborhood: str
The neighborhood connectivity of the skeleton. Can be “n4”, “n6”, “n8”, “n18”, or “n26”.
Returns:#
- adjacency_matrices: list
A list of adjacency matrices for each skeleton in the image.
- napari_toska.convert_adjacency_matrix_to_graph(adj_mat: ndarray, weights: ndarray | None = None) Graph[source]#
Convert an adjacency matrix to a networkx graph.
- Parameters:
adj_mat (numpy.ndarray) – An adjacency matrix where each row represents a branching- or endpoint and each column represents a branch. A value of 1 indicates that the branching point or endpoint is connected to the branch.
weights (numpy.ndarray, optional) – An array of weights for each branch, by default 1 (unweighted)
- Returns:
G – A networkx graph where each node represents a branching- or endpoint and each edge represents a branch.
- Return type:
networkx.Graph
- napari_toska.create_spine_image(adjacency_matrix: ndarray, labeled_branches: napari.types.LabelsData) napari.types.LabelsData[source]#
Create an image where the pixels of the spine are labeled with the branch ID of the branch they belong to.
- Parameters:
labeled_branches (napari.types.LabelsData) – A labeled image with labelled skeleton branches.
img_spine_ids (list) – A list of branch labels that represent a path in a skeleton graph.
- Returns:
img_spine – A labeled image with the same shape as labeled_branches where the pixels of the spine are labeled with the branch ID of the branch they belong to.
- Return type:
napari.types.LabelsData