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.

Other Parameters
  • 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.

Other Parameters
  • 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.

Other Parameters
  • 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, 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 to csr_graph.shape[0].

Other Parameters
  • 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 than np.max(coordinates, axis=0).

  • **kwargs (keyword arguments) – Arguments passed on to nx.draw_networkx. Particularly useful ones include node_size= and font_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.

Other Parameters
  • 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

1

http://scikit-image.org/docs/dev/user_guide/data_types.html

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)