elektronn2.malis package

Submodules

elektronn2.malis.malis_utils module

elektronn2.malis.malis_utils.compute_V_rand_N2(seg_true, seg_pred)[source]

Computes Rand index of seg_pred w.r.t seg_true. Small is better!!! The input arrays both contain label IDs and may be of arbitrary, but equal, shape.

Pixels which are have ID in the true segmentation are not counted!

Parameters:

seg_true: np.ndarray
True segmentation, IDs
seg_pred: np.ndarray
Predicted segmentation
Returns:ri
Return type:???
elektronn2.malis.malis_utils.mknhood2d(radius=1)[source]

Makes nhood structures for some most used dense graphs

elektronn2.malis.malis_utils.mknhood3d(radius=1)[source]

Makes nhood structures for some most used dense graphs. The neighborhood reference for the dense graph representation we use nhood(1,:) is a 3 vector that describe the node that conn(:,:,:,1) connects to so to use it: conn(23,12,42,3) is the edge between node [23 12 42] and [23 12 42]+nhood(3,:) See? It’s simple! nhood is just the offset vector that the edge corresponds to.

elektronn2.malis.malis_utils.mknhood3d_aniso(radiusxy=1, radiusxy_zminus1=1.8)[source]

Makes nhood structures for some most used dense graphs.

elektronn2.malis.malis_utils.bmap_to_affgraph(bmap, nhood)[source]

Construct an affinity graph from a boundary map

The spatial shape of the affinity graph is the same as of seg_gt. This means that some edges are are undefined and therefore treated as disconnected. If the offsets in nhood are positive, the edges with largest spatial index are undefined.

Parameters:
  • bmap (3d np.ndarray, int) – Volume of boundaries 0: object interior, 1: boundaries / ECS
  • nhood (2d np.ndarray, int) – Neighbourhood pattern specifying the edges in the affinity graph Shape: (#edges, ndim) nhood[i] contains the displacement coordinates of edge i The number and order of edges is arbitrary
Returns:

aff – Affinity graph of shape (#edges, x, y, z) 1: connected, 0: disconnected

Return type:

4d np.ndarray int32

elektronn2.malis.malis_utils.seg_to_affgraph(seg_gt, nhood)[source]

Construct an affinity graph from a segmentation (IDs)

Segments with ID 0 are regarded as disconnected The spatial shape of the affinity graph is the same as of seg_gt. This means that some edges are are undefined and therefore treated as disconnected. If the offsets in nhood are positive, the edges with largest spatial index are undefined.

Parameters:
  • seg_gt (3d np.ndarray, int (any precision)) – Volume of segmentation IDs
  • nhood (2d np.ndarray, int) – Neighbourhood pattern specifying the edges in the affinity graph Shape: (#edges, ndim) nhood[i] contains the displacement coordinates of edge i The number and order of edges is arbitrary
Returns:

aff – Affinity graph of shape (#edges, x, y, z) 1: connected, 0: disconnected

Return type:

4d np.ndarray int16

elektronn2.malis.malis_utils.watershed_from_affgraph(aff, seeds, nhood)[source]
elektronn2.malis.malis_utils.bmappred_to_affgraph(pred, nhood)[source]

Construct an affinity graph from boundary predictions

Parameters:
  • pred (3d np.ndarray) – Volume of boundary predictions
  • nhood (2d np.ndarray, int) – Neighbourhood pattern specifying the edges in the affinity graph Shape: (#edges, ndim) nhood[i] contains the displacement coordinates of edge i The number and order of edges is arbitrary
Returns:

aff – Affinity graph of shape (#edges, x, y, z) 1: connected, 0: disconnected

Return type:

4d np.ndarray int16

elektronn2.malis.malisop module

elektronn2.malis.malisop.malis_weights(affinity_pred, affinity_gt, seg_gt, nhood, unrestrict_neg=False)[source]

Computes MALIS loss weights

Roughly speaking the malis weights quantify the impact of an edge in the predicted affinity graph on the resulting segmentation.

Parameters:
  • affinity_pred (4d np.ndarray float32) – Affinity graph of shape (#edges, x, y, z) 1: connected, 0: disconnected
  • affinity_gt (4d np.ndarray int16) – Affinity graph of shape (#edges, x, y, z) 1: connected, 0: disconnected
  • seg_gt (3d np.ndarray, int (any precision)) – Volume of segmentation IDs
  • nhood (2d np.ndarray, int) – Neighbourhood pattern specifying the edges in the affinity graph Shape: (#edges, ndim) nhood[i] contains the displacement coordinates of edge i The number and order of edges is arbitrary
  • unrestrict_neg (Bool) – Use this to relax the restriction on neg_counts. The restriction modifies the edge weights for before calculating the negative counts as: edge_weights_neg = np.maximum(affinity_pred, affinity_gt) If unrestricted the predictions are used directly.
Returns:

  • pos_counts (4d np.ndarray int32) – Impact counts for edges that should be 1 (connect)
  • neg_counts (4d np.ndarray int32) – Impact counts for edges that should be 0 (disconnect)

  • Computes for all pixel-pairs the MaxiMin-Affinity
  • Separately for pixel-pairs that should/should not be connected
  • Every time an affinity prediction is a MaxiMin-Affinity its weight is incremented by one in the output matrix (in different slices depending on whether that that pair should/should not be connected)

Module contents