gala.viz: Visualization tools¶
-
gala.viz.
add_nats_to_plot
(ars, tss, stops=0.5, colors='k', markers='o', **kwargs)[source]¶ In an existing active split-vi plot, add the natural stopping point.
By default, a circle marker is used.
Parameters: ars : list of numpy arrays
Each array has shape (2, N) and represents a split-VI curve, with ars[i][0] holding the undersegmentation and ars[i][1] holding the oversegmentation for each i.
tss : list of numpy arrays
Each array has shape (N,) and represents the algorithm threshold that gave rise to the VI measurements in ars.
stops : float, optional
The natural stopping point for the algorithm. For example, if an algorithm merges segments according to a merge probability, the natural stopping point is at $p=0.5$, when there are even odds of the merge being a true merge.
colors : string, list of string, or list of float tuple, optional
A color specification or list of color specifications. If there are fewer colors than split-VI arrays, the colors are cycled.
markers : string, or list of string, optional
Point marker specification (as defined in matplotlib) or list thereof. As with colors, if there are fewer markers than VI arrays, the markers are cycled.
**kwargs : dict (string keys), optional
Keyword arguments to be passed through to matplotlib.pyplot.scatter.
Returns: points : list of matplotlib.collections.PathCollection
The points returned by each of the calls to scatter.
-
gala.viz.
add_opts_to_plot
(ars, colors='k', markers='^', **kwargs)[source]¶ In an existing active split-vi plot, add the point of optimal VI.
By default, a star marker is used.
Parameters: ars : list of numpy arrays
Each array has shape (2, N) and represents a split-VI curve, with ars[i][0] holding the undersegmentation and ars[i][1] holding the oversegmentation for each i.
colors : string, list of string, or list of float tuple, optional
A color specification or list of color specifications. If there are fewer colors than split-VI arrays, the colors are cycled.
markers : string, or list of string, optional
Point marker specification (as defined in matplotlib) or list thereof. As with colors, if there are fewer markers than VI arrays, the markers are cycled.
**kwargs : dict (string keys), optional
Keyword arguments to be passed through to matplotlib.pyplot.scatter.
Returns: points : list of matplotlib.collections.PathCollection
The points returned by each of the calls to scatter.
-
gala.viz.
display_3d_segmentations
(segs, image=None, probability_map=None, axis=0, z=None, fignum=None)[source]¶ Show slices of multiple 3D segmentations.
Parameters: segs : list or tuple of np.ndarray of int, shape (M, N, P)
The segmentations to be examined.
image : np.ndarray, shape (M, N, P[, 3]), optional
The image corresponding to the segmentations.
probability_map : np.ndarray, shape (M, N, P), optional
The segment boundary probability map.
axis : int in {0, 1, 2}, optional
The axis along which to show a slice of the segmentation.
z : int in [0, (M, N, P)[axis]), optional
The slice to display. Defaults to the middle slice.
fignum : int, optional
Which figure number to use. Uses the default (new figure) if none is provided.
Returns: fig : plt.Figure
The figure handle.
-
gala.viz.
draw_seg
(seg, im)[source]¶ Return a segmentation map matching the original image color.
Parameters: seg : np.ndarray of int, shape (M, N, …)
The segmentation to be displayed
im : np.ndarray, shape (M, N, …, C)
The image corresponding to the segmentation.
Returns: out : np.ndarray, same shape and type as im.
An image where each segment has uniform color.
Examples
>>> a = np.array([[1, 1, 2, 2], ... [1, 2, 2, 3], ... [2, 2, 3, 3]]) >>> g = np.array([[0.5, 0.2, 1.0, 0.9], ... [0.2, 0.8, 0.9, 0.6], ... [0.9, 0.9, 0.4, 0.5]]) >>> draw_seg(a, g) array([[ 0.3, 0.3, 0.9, 0.9], [ 0.3, 0.9, 0.9, 0.5], [ 0.9, 0.9, 0.5, 0.5]])
-
gala.viz.
imshow_grey
(im, axis=None)[source]¶ Show a segmentation using a gray colormap.
Parameters: im : np.ndarray of int, shape (M, N)
The segmentation to be displayed.
Returns: fig : plt.Figure
The image shown.
-
gala.viz.
imshow_magma
(im, axis=None)[source]¶ Show a segmentation using a magma colormap.
Parameters: im : np.ndarray of int, shape (M, N)
The segmentation to be displayed.
Returns: fig : plt.Figure
The image shown.
-
gala.viz.
imshow_rand
(im, axis=None, labrandom=True)[source]¶ Show a segmentation using a random colormap.
Parameters: im : np.ndarray of int, shape (M, N)
The segmentation to be displayed.
labrandom : bool, optional
Use random points in the Lab colorspace instead of RGB.
Returns: fig : plt.Figure
The image shown.
-
gala.viz.
plot_decision_function
(clf, data_range=None, features=None, labels=None, feature_columns=[0, 1], n_gridpoints=201)[source]¶ Plot the decision function of a classifier in 2D.
Parameters: clf : scikit-learn classifier
The classifier to be evaluated.
data_range : tuple of int, optional
The range of values to be evaluated.
features : 2D array of float, optional
The features of the training data.
labels : 1D array of int, optional
The labels of the training data.
feature_columns : tuple of int, optional
Which feature columns to plot, if there are more than two.
n_gridpoints : int, optional
The number of points to place on each dimension of the 2D grid.
-
gala.viz.
plot_split_vi
(ars, best=None, colors='k', linespecs='-', **kwargs)[source]¶ Make a split-VI plot.
The split-VI plot was introduced in Nunez-Iglesias et al, 2013 [1]
Parameters: ars : array or list of arrays of float, shape (2, N)
The input VI arrays. ars[i][0] should contain the undersegmentation and ars[i][1] the oversegmentation.
best : array-like of float, len=2, optional
Agglomerative segmentations can’t get to (0, 0) VI if the starting superpixels are not perfectly aligned with the gold standard segmentation. Therefore, there is a point of best achievable VI. best should contain the coordinates of this point.
colors : matplotlib color specification or list thereof, optional
The color of each line being plotted. If there are fewer colors than arrays, they are cycled.
linespecs : matplotlib line type spec, or list thereof, optional
The line type to plot with (‘-‘, ‘–’, ‘-.’, etc).
kwargs : dict, string keys, optional
Additional keyword arguments to pass through to plt.plot.
Returns: lines : matplotlib Lines2D object(s)
The lines plotted.
-
gala.viz.
plot_vi
(g, history, gt, fig=None)[source]¶ Plot the VI from segmentations based on Rag and sequence of merges.
Parameters: g : agglo.Rag object
The region adjacency graph.
history : list of tuples
The merge history of the RAG.
gt : np.ndarray
The ground truth corresponding to the RAG.
fig : plt.Figure, optional
Use this figure for plotting. If not provided, a new figure is created.
Returns: None
-
gala.viz.
plot_vi_breakdown
(seg, gt, ignore_seg=[], ignore_gt=[], hlines=None, subplot=False, figsize=None, **kwargs)[source]¶ Plot conditional entropy H(Y|X) vs P(X) for both seg|gt and gt|seg.
Parameters: seg : np.ndarray of int, shape (M, [N, …, P])
The automatic (candidate) segmentation.
gt : np.ndarray of int, shape (M, [N, …, P]) (same as seg)
The gold standard/ground truth segmentation.
ignore_seg : list of int, optional
Ignore segments in this list from the automatic segmentation during evaluation and plotting.
ignore_gt : list of int, optional
Ignore segments in this list from the ground truth segmentation during evaluation and plotting.
hlines : int, optional
Plot this many isoclines between the minimum and maximum VI contributions.
subplot : bool, optional
If True, plot oversegmentation and undersegmentation in separate subplots.
figsize : tuple of float, optional
The figure width and height, in inches.
**kwargs : dict
Additional keyword arguments for matplotlib.pyplot.plot.
Returns: None
-
gala.viz.
plot_vi_breakdown_panel
(px, h, title, xlab, ylab, hlines, scatter_size, **kwargs)[source]¶ Plot a single panel (over or undersegmentation) of VI breakdown plot.
Parameters: px : np.ndarray of float, shape (N,)
The probability (size) of each segment.
h : np.ndarray of float, shape (N,)
The conditional entropy of that segment.
title, xlab, ylab : string
Parameters for matplotlib.plt.plot.
hlines : iterable of float
Plot hyperbolic lines of same VI contribution. For each value v in hlines, draw the line h = v/px.
scatter_size : int, optional
**kwargs : dict
Additional keyword arguments for matplotlib.pyplot.plot.
Returns: None
-
gala.viz.
show_multiple_images
(*images, axes=None, image_type='raw')[source]¶ Returns a figure with subplots containing multiple images.
Parameters: images : np.ndarray of int, shape (M, N)
The input images to be displayed.
axes: matplotlib.AxesImage, optional
Whether to pass in multiple axes. Must be equal to the number of input images.
image_type : string, optional
Displays the images with different colormaps. Set to display ‘raw’ by default. Other options that are accepted are ‘grey’ and ‘magma’, or ‘rand’.
Returns: fig : plt.Figure
The image shown.