skan.draw: Skeleton visualisation#
- skan.draw.overlay_euclidean_skeleton_2d(image, stats, *, image_cmap=None, skeleton_color_source='branch_type', skeleton_colormap='viridis', axes=None)[source]#
Plot the image, and overlay the straight-line skeleton over it.
- Parameters:
image (array, shape (M, N)) â The input image.
stats (array, shape (M, N)) â Skeleton statistics.
image_cmap (matplotlib colormap name or object, optional) â The colormap to use for the input image. Defaults to grayscale.
skeleton_color_source (string, optional) â
The name of the column to use for the skeleton edge color. See the output of skan.summarise for valid choices. Most common choices would be:
skeleton-id: each individual skeleton (connected component) will have a different colour.
branch_type: each branch type (tip-tip, tip-junction, junction-junction, path-path). This is the default.
branch-distance: the curved length of the skeleton branch.
euclidean-distance: the straight-line length of the skeleton branch.
skeleton_colormap (matplotlib colormap name or object, optional) â The colormap for the skeleton values.
axes (matplotlib Axes object, optional) â An Axes object on which to draw. If None, a new one is created.
- Returns:
axes â The Axes on which the plot is drawn.
- Return type:
matplotlib Axes object
- skan.draw.overlay_skeleton_2d(image, skeleton, *, image_cmap=None, color=(1, 0, 0), alpha=1, dilate=0, axes=None)[source]#
Overlay the skeleton pixels on the input image.
- Parameters:
image (array, shape (M, N[, 3])) â The input image. Can be grayscale or RGB.
skeleton (array, shape (M, N)) â The input 1-pixel-wide skeleton.
image_cmap (matplotlib colormap name or object, optional) â If the input image is grayscale, colormap it with this colormap. The default is grayscale.
color (tuple of float in [0, 1], optional) â The RGB color for the skeleton pixels.
alpha (float, optional) â Blend the skeleton pixels with the given alpha.
dilate (int, optional) â Dilate the skeleton by this amount. This is useful when rendering large images where aliasing may cause some pixels of the skeleton not to be drawn.
axes (matplotlib Axes) â The Axes on which to plot the image. If None, new ones are created.
- Returns:
axes â The Axis on which the image is drawn.
- Return type:
matplotlib Axes
- skan.draw.overlay_skeleton_2d_class(skeleton, *, image_cmap='gray', skeleton_color_source='path_means', skeleton_colormap='viridis', vmin=None, vmax=None, axes=None)[source]#
Plot the image, and overlay the skeleton over it.
- Parameters:
skeleton (skan.Skeleton object) â The input skeleton, which contains both the skeleton and the source image.
image_cmap (matplotlib colormap name or object, optional) â The colormap to use for the input image. Defaults to grayscale.
skeleton_color_source (string or callable, optional) â
The name of the method to use for the skeleton edge color. See the documentation of skan.Skeleton for valid choices. Most common choices would be:
path_means: the mean value of the skeleton along each path.
path_lengths: the length of each path.
path_stdev: the standard deviation of pixel values along the path.
Alternatively, a callable can be provided that takes as input a Skeleton object and outputs a list of floating point values of the same length as the number of paths.
skeleton_colormap (matplotlib colormap name or object, optional) â The colormap for the skeleton values.
vmin (float, optional) â The minimum and maximum values for the colormap. Use this to pin the colormapped values to a certain range.
vmax (float, optional) â The minimum and maximum values for the colormap. Use this to pin the colormapped values to a certain range.
axes (matplotlib Axes object, optional) â An Axes object on which to draw. If None, a new one is created.
- Returns:
axes (matplotlib Axes object) â The Axes on which the plot is drawn.
mappable (matplotlib ScalarMappable object) â The mappable values corresponding to the line colors. This can be used to create a colorbar for the plot.
- skan.draw.overlay_skeleton_networkx(csr_graph, coordinates, *, axis=None, image=None, cmap=None, **kwargs)[source]#
Draw the skeleton as a NetworkX graph, optionally overlaid on an image.
Due to the size of NetworkX drawing elements, this is only recommended for very small skeletons.
- Parameters:
csr_graph (SciPy Sparse matrix) â The skeleton graph in SciPy CSR format.
coordinates (array, shape (N_points, 2)) â The coordinates of each point in the skeleton.
coordinates.shape[0]
should be equal tocsr_graph.shape[0]
.axis (Matplotlib Axes object, optional) â The Axes on which to plot the data. If None, a new figure and axes will be created.
image (array, shape (M, N[, 3])) â An image on which to overlay the skeleton.
image.shape
should be greater thannp.max(coordinates, axis=0)
.**kwargs (keyword arguments) â Arguments passed on to nx.draw_networkx. Particularly useful ones include
node_size=
andfont_size=
.
- skan.draw.pipeline_plot(image, thresholded, skeleton, stats, *, figure=None, axes=None, figsize=(9, 9))[source]#
Draw the image, the thresholded version, and its skeleton.
- Parameters:
image (array, shape (M, N, ...[, 3])) â Input image, conformant with scikit-image data type specification [1].
thresholded (array, same shape as image) â Binarized version of the input image.
skeleton (array, same shape as image) â Skeletonized version of the input image.
stats (pandas DataFrame) â Skeleton statistics from the input image/skeleton.
figure (matplotlib Figure, optional) â If given, where to make the plots.
axes (array of matplotlib Axes, optional) â If given, use these axes to draw the plots. Should have len 4.
figsize (2-tuple of float, optional) â The width and height of the figure.
smooth_method ({'Gaussian', 'TV', 'NL'}, optional) â Which denoising method to use on the image.
- Returns:
fig (matplotlib Figure) â The Figure containing all the plots
axes (array of matplotlib Axes) â The four axes containing the drawn images.
References
- skan.draw.pixel_perfect_figsize(image, dpi=80)[source]#
Return the Matplotlib figure size tuple (w, h) for given image and dpi.
- Parameters:
image (array, shape (M, N[, 3])) â The image to be plotted.
dpi (int, optional) â The desired figure dpi.
- Returns:
figsize â The desired figure size.
- Return type:
tuple of float
Examples
>>> image = np.empty((768, 1024)) >>> pixel_perfect_figsize(image) (12.8, 9.6)
- skan.draw.sholl_shells(center, radii, *, axes=None, **kwargs)[source]#
Draw concentric circles around a center point.
- Parameters:
center (array of float, shape (2,)) â The center of the circles. This should be in NumPy-style row/column coordinates.
radii (array of float, shape (N,)) â The radii of the concentric circles.
axes (matplotlib Axes, optional) â The axes on which to draw the circles. If None, create a new instance.
- Returns:
axes (matplotlib Axes) â The axes on which the circles were drawn
patches (list of matplotlib Patches) â The patch objects that were drawn.
Notes
Additional keyword arguments are passed directly to the matplotlib.patches.Circle call. Valid keywords include
edgecolor
,linestyle
, and linewidth`. See matplotlib documentation for details.