Skip to main content

Python package for evaluating neuron segmentations in terms of the number of splits and merges

Project description

SkeletonMetrics

License Code Style

semantic-release: angular

Python package that evaluates the topological accuracy of a predicted neuron segmentation by comparing it to a set of ground truth skeletons (i.e. graphs). Topological errors (e.g. splits and merges) are detected by examining skeleton edges and checking if the corresponding nodes belong to the same object in the segmentation. Once the accuracy of each edge has been determined, several skeleton-based metrics are computed to quantify the topological accuracy.

Note: This repository is an implementation of the skeleton-based metrics described in High-Precision Automated Reconstruction of Neurons with Flood-filling Networks

Overview

The pipeline for computing skeleton metrics consists of three main steps:

1. Label Graphs: Nodes in ground truth graphs are labeled with segmentation IDs.

2. Error Detection: Compare labels of neighboring nodes to detect mistakes.

3. Compute Metrics: Update graph structure by removing omit nodes and compute skeleton-based metrics.


pipeline
Figure: Visualization of skeleton metric computation pipeline, see Method section for description of each step.

Method

Step 1: Label Graphs

The process starts with a collection of ground truth graphs, each stored as an individual SWC file, where the "xyz" attribute represents voxel coordinates in an image. Each ground truth graph is loaded and represented as a custom NetworkX graph with these coordinates as a node-level attribute. The nodes of each graph are then labeled with their corresponding segment IDs from the predicted segmentation.


Figure: On the left, ground truth graphs are superimposed on a segmentation where colors represent segment IDs. On the right, the nodes of the graphs have been labeled with the corresponding segment IDs.

Step 2: Error Detection

Topological mistakes detected in skeleton
Figure: From top to bottom: correct edge (nodes have same segment ID), omit edge (at least one node does not have a segment ID), split edge (nodes have different segment IDs), merged edge (segment intersects with multiple graphs).

Step 3: Compute Metrics

Lastly, we compute the following skeleton-based metrics:

  • # Splits: Number of connected components (minus 1) in a graph after removing omit and split edges.
  • # Merges: Number of merge mistakes.
  • % Split Edges: Percentage of split edges.
  • % Omit Edges: Percentage of omit edges.
  • % Merged Edges: Percentage of merged edges.
  • Expected Run Length (ERL): Expected run length of graph after removing omit, split, and merged edges.
  • Normalized ERL: ERL normalized by the total run length of the graph.
  • Edge Accuracy: Percentage of edges that are correct.
  • Split Rate: Run length of the graph divided by number of splits.
  • Merge Rate: Run length of the graph divided by number of merges.

Installation

To use the software, in the root directory, run

pip install -e .

Usage

Here is a simple example of evaluating a predicted segmentation.

from segmentation_skeleton_metrics.evaluate import evaluate
from segmentation_skeleton_metrics.utils.img_util import TiffReader


# Initializations
output_dir = "./"
segmentation_path = "path-to-predicted-segmentation"
fragments_pointer = "path-to-predicted-skeletons"
groundtruth_pointer = "path-to-groundtruth-skeletons"

# Run
segmentation = TiffReader(segmentation_path)
evaluate(
   groundtruth_pointer,
   segmentation,
   output_dir,
   fragments_pointer=fragments_pointer,
)


Figure: Example of printouts generated after running evaluation.


Note: this package can also be used to evaluate a segmentation in which split mistakes have been corrected.

Contact Information

For any inquiries, feedback, or contributions, please do not hesitate to contact us. You can reach us via email at anna.grim@alleninstitute.org or connect on LinkedIn.

License

segmentation-skeleton-metrics is licensed under the MIT License.

Project details


Release history Release notifications | RSS feed

This version

5.7.9

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segmentation_skeleton_metrics-5.7.9.tar.gz (727.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

segmentation_skeleton_metrics-5.7.9-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file segmentation_skeleton_metrics-5.7.9.tar.gz.

File metadata

File hashes

Hashes for segmentation_skeleton_metrics-5.7.9.tar.gz
Algorithm Hash digest
SHA256 41af713891b19da39914345a7086c65c1bc29f61e36ca01d8a5e30f7b39c95fb
MD5 7ce237bd84727ec6b8f5cc94a203cec0
BLAKE2b-256 718a57b36c0f139c485dd3ce9db58aec679889aef63f1aac34a1e594ec13d42b

See more details on using hashes here.

File details

Details for the file segmentation_skeleton_metrics-5.7.9-py3-none-any.whl.

File metadata

File hashes

Hashes for segmentation_skeleton_metrics-5.7.9-py3-none-any.whl
Algorithm Hash digest
SHA256 59255244a956e5753e2319bdf7cb9270cd4fbe27f62b734274c500daca379812
MD5 b03025918f9e73b8b8dec2f1b6126e04
BLAKE2b-256 2d39a49e715c2314c3c21d48a852daf35ddfbf1556b97f8df1d000db0fcbb098

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page