Skip to content

A Python package for detecting somas in ExaSPIM image datasets. Includes tools for image preprocessing and deep learning-based classification and training.

License

Notifications You must be signed in to change notification settings

AllenNeuralDynamics/aind-exaspim-soma-detection

Repository files navigation

aind-exaspim-soma-detection

License Code Style semantic-release: angular Interrogate Coverage Python

Overview

This repository implements a pipeline for detecting somas in whole-brain images. It utilizes a multi-step approach to propose, filter, and classify potential soma locations. This method prioritizes high recall in the initial proposal generation, followed by filtering based on prior knowledge of soma characteristics, and finally refines the proposals using a convolutional neural network (CNN) for classification.

The soma detection pipeline consists of three main steps:

a. Proposal Generation: Detects blob-like structures to generate initial soma proposals.

b. Proposal Filtering: Filters out trivial false positives using heuristics and prior knowledge of soma characteristics.

c. Proposal Classification: Classify proposals with a convolutional neural network (CNN).


pipeline
Figure: Visualization of soma detection pipeline, see Inference section for description of each step.

Usage

Here is an example of calling the main routine to run the full pipeline.

if __name__ == "__main__":
    # Initializations
    brain_id = "unique-identifier-of-dataset"
    img_prefix = "path-to-image"

    # Parameters - Proposal Generation
    multiscale_1 = 4
    patch_shape_1 = (64, 64, 64)
    bright_threshold = 100
    overlap = (28, 28, 28)
    save_proposals_bool = True

    # Parameters - Proposal Classification
    multiscale_2 = 1
    patch_shape_2 = (102, 102, 102)
    accept_threshold = 0.4
    model_path = "path-to-model"
    save_somas_bool = True

    # Main
    main()

Inference

Step 1: Proposal Generation

The goal of this step is to generate initial proposals for soma locations by detecting blob-like structures in the image. The proposal generation algorithm consists of the following steps

a. Smooth image with Gaussian filter to reduce false positives.

b. Laplacian of Gaussian (LoG) with multiple sigmas to enhance regions where the gradient changes rapidly, then apply a max filter.

c. Generate initial set of proposals by detecting local maximas.

d. Shift each proposal to the brightest voxel in its neighborhood and reject it if the brightness is below a threshold.

proposals
Figure: Proposals generated across a large region.

Step 2: Proposal Filtering

The initial proposal generation step prioritizes high recall, which results in many false positives. This step leverages prior knowledge, such as the Gaussian-like appearance and expected size of somas, to filter out trivial false positives.

a. Merges proposals within a given distance threshold.

b. If the number of proposals exceeds a certain threshold, the top k brightest proposals are kept.

c. Fit Gaussian to neighborhood centered at proposal and compute fitness score by comparing fitted Gaussian to image values. Proposals are discarded if (1) fitness score is below threshold or (2) estimated standard deviation is out of range.

proposals
Figure: Examples of filtered proposals.

Step 3: Proposal Classification

Finally, the remaining proposals are classified by a neural network that generates soma likelihoods. Proposals with a likelihood above a given threshold are accepted as soma locations.

detections
Figure: Detected somas across a large region.

Installation

To use the software, in the root directory, run

pip install -e .

License

aind-exaspim-soma-detection is licensed under the MIT License.

About

A Python package for detecting somas in ExaSPIM image datasets. Includes tools for image preprocessing and deep learning-based classification and training.

Resources

License

Stars

Watchers

Forks

Packages

No packages published