Cells#

Expert cell image processing pipeline.

This module provides the basic routines for processing immediate early gene data.

The routines are used in the ClearMap.Scripts.CellMap pipeline.

detect_cells(source, sink=None, cell_detection_parameter={'background_correction': {'form': 'Disk', 'save': False, 'shape': (10, 10)}, 'dog_filter': {'shape': None, 'sigma': None, 'sigma2': None}, 'equalization': None, 'illumination_correction': {'flatfield': None, 'scaling': 'mean'}, 'intensity_detection': {'measure': ['source', 'background_correction'], 'method': 'max', 'shape': 3}, 'maxima_detection': {'h_max': None, 'save': False, 'shape': 5, 'threshold': 0, 'valid': True}, 'shape_detection': {'save': False, 'threshold': 700}}, processing_parameter={'axes': [2], 'optimization': True, 'optimization_fix': 'all', 'overlap': 32, 'processes': None, 'size_max': 100, 'size_min': 50, 'verbose': None}, workspace=None)[source]#

Cell detection pipeline.

Arguments

sourcesource specification

The source of the stitched raw data.

sinksink specification or None

The sink to write the result to. If None, an array is returned.

cell_detection_parameterdict

Parameter for the binarization. See below for details.

processing_parameterdict

Parameter for the parallel processing. See ClearMap.ParallelProcessing.BlockProcessing.process() for description of all the parameter.

workspace: Workspace

The optional workspace object to have a handle to cancel the multiprocess

Returns

sinkSource

The result of the cell detection.

Notes

Effectively this function performs the following steps:
  • illumination correction via correct_illumination()

  • background removal

  • difference of Gaussians (DoG) filter

  • maxima detection via find_extended_maxima()

  • cell shape detection via detect_shape()

  • cell intensity and size measurements via:

    find_intensity(), find_size().

The parameters for each step are passed as sub-dictionaries to the cell_detection_parameter dictionary.

  • If None is passed for one of the steps this step is skipped.

  • Each step also has an additional parameter ‘save’ that enables saving

    of the result of that step to a file to inspect the pipeline.

Illumination correction

illumination_correctiondict or None

Illumination correction step parameter.

flatfieldarray or str

The flat field estimate for the image planes.

backgroundarray or None

A background level to assume for the flatfield correction.

scalingfloat, ‘max’, ‘mean’ or None

Optional scaling after the flat field correction.

savestr or None

Save the result of this step to the specified file if not None.

See also ClearMap.ImageProcessing.IlluminationCorrection.correct_illumination()

Background removal

background_correctiondict or None

Background removal step parameter.

shapetuple

The shape of the structure element to estimate the background. This should be larger than the typical cell size.

formstr

The form of the structure element (e.g. ‘Disk’)

savestr or None

Save the result of this step to the specified file if not None.

Equalization

equalizationdict or None

Equalization step parameter. See also ClearMap.ImageProcessing.LocalStatistics.local_percentile()

percentiletuple

The lower and upper percentiles used to estimate the equalization. The lower percentile is used for normalization, the upper to limit the maximal boost to a maximal intensity above this percentile.

max_valuefloat

The maximal intensity value in the equalized image.

selemtuple

The structural element size to estimate the percentiles. Should be larger than the larger vessels.

spacingtuple

The spacing used to move the structural elements. Larger spacings speed up processing but become locally less precise.

interpolateint

The order of the interpolation used in constructing the full background estimate in case a non-trivial spacing is used.

savestr or None

Save the result of this step to the specified file if not None.

DoG Filter

dog_filterdict or None

Difference of Gaussian filter step parameter.

shapetuple

The shape of the filter. This should be near the typical cell size.

sigmatuple or None

The std of the inner Gaussian. If None, determined automatically from shape.

sigma2tuple or None

The std of the outer Gaussian. If None, determined automatically from shape.

savestr or None

Save the result of this step to the specified file if not None.

Maxima detection

maxima_detectiondict or None

Extended maxima detection step parameter.

h_maxfloat or None

The ‘height’ for the extended maxima. If None, simple local maxima detection is used.

shapetuple

The shape of the structural element for extended maxima detection. This should be near the typical cell size.

thresholdfloat or None

Only maxima above this threshold are detected. If None, all maxima are detected.

validbool

If True, only detect cell centers in the valid range of the blocks with overlap.

savestr or None

Save the result of this step to the specified file if not None.

Shape detection

shape_detectiondict or None

Shape detection step parameter.

thresholdfloat

Cell shape is expanded from maxima if pixels are above this threshold and not closer to another maxima.

savestr or None

Save the result of this step to the specified file if not None.

Intensity detection

intensity_detectiondict or None

Intensity detection step parameter.

method{‘max’|’min’,’mean’|’sum’}

The method to use to measure the intensity of a cell.

shapetuple or None

If no cell shapes are detected a disk of this shape is used to measure the cell intensity.

savestr or None

Save the result of this step to the specified file if not None.

References

[1] Renier, Adams, Kirst, Wu et al., “Mapping of Brain Activity by Automated Volume Analysis of Immediate Early Genes.”, Cell 165, 1789 (2016) [1] Kirst et al., “Mapping the Fine-Scale Organization and Plasticity of the Brain Vasculature”, Cell 180, 780 (2020)

detect_cells_block(source, parameter={'background_correction': {'form': 'Disk', 'save': False, 'shape': (10, 10)}, 'dog_filter': {'shape': None, 'sigma': None, 'sigma2': None}, 'equalization': None, 'illumination_correction': {'flatfield': None, 'scaling': 'mean'}, 'intensity_detection': {'measure': ['source', 'background_correction'], 'method': 'max', 'shape': 3}, 'maxima_detection': {'h_max': None, 'save': False, 'shape': 5, 'threshold': 0, 'valid': True}, 'shape_detection': {'save': False, 'threshold': 700}}, n_threads=None)[source]#

Detect cells in a Block.

detect_maxima(source, h_max=None, shape=5, threshold=None, verbose=False)[source]#
dog_filter(source, shape, sigma=None, sigma2=None)[source]#
equalize(source, percentile=(0.5, 0.95), max_value=1.5, selem=(200, 200, 5), spacing=(50, 50, 5), interpolate=1, mask=None)[source]#
filter_cells(source, sink, thresholds)[source]#

Filter an array of detected cells according to the thresholds.

Arguments

sourcestr, array or Source

The source for the cell data.

sinkstr, array or Source

The sink for the results.

thresholdsdict

Dictionary of the form {name : threshold} where name refers to the column in the cell data and threshold can be None, a float indicating a minimal threshold or a tuple (min, max) where min, max can be None or a minimal and maximal threshold value.

Returns

sinkstr, array or Source

The thresholded cell data.

remove_background(source, shape, form='Disk')[source]#
default_cell_detection_parameter = {'background_correction': {'form': 'Disk', 'save': False, 'shape': (10, 10)}, 'dog_filter': {'shape': None, 'sigma': None, 'sigma2': None}, 'equalization': None, 'illumination_correction': {'flatfield': None, 'scaling': 'mean'}, 'intensity_detection': {'measure': ['source', 'background_correction'], 'method': 'max', 'shape': 3}, 'maxima_detection': {'h_max': None, 'save': False, 'shape': 5, 'threshold': 0, 'valid': True}, 'shape_detection': {'save': False, 'threshold': 700}}#

Parameter for the cell detection pipeline. See detect_cells() for details.

default_cell_detection_processing_parameter = {'axes': [2], 'optimization': True, 'optimization_fix': 'all', 'overlap': 32, 'processes': None, 'size_max': 100, 'size_min': 50, 'verbose': None}#

Parallel processing parameter for the cell detection pipeline. See ClearMap.ParallelProcessing.BlockProcessing.process() for details.