hnccorr.base module¶
Base components of HNCcorr.
-
class
hnccorr.base.
Candidate
(center_seed, hnccorr)[source]¶ Bases:
object
Encapsulates the logic for segmenting a single cell candidate / seed.
- Variables
best_segmentation (Segmentation) – Segmentation of a cell’s spatial footprint as selected by the postprocessor.
center_seed (tuple) – Seed pixel coordinates.
clean_segmentations (list[Segmentation]) – List of segmentation after calling clean() on each segmentation.
segmentations (list[Segmentation]) – List of segmentations returned by HNC.
_hnccorr (HNCcorr) – HNCcorr object.
-
segment
()[source]¶ Segment candidate cell and return footprint (if any).
Encapsulates the procedure for segmenting a single cell candidate. It determines the seeds, constructs the similarity graph, and solves the HNC clustering problem for all values of the trade-off parameter lambda. The postprocessor selects the best segmentation or determines that no cell is found.
- Returns
Best segmentation or None if no cell is found.
- Return type
Segmentation or None
-
class
hnccorr.base.
HNCcorr
(seeder, postprocessor, segmentor, positive_seed_selector, negative_seed_selector, graph_constructor, candidate_class, patch_class, embedding_class, patch_size)[source]¶ Bases:
object
Implementation of the HNCcorr algorithm.
This class specifies all components of the algoritm and defines the procedure for segmenting the movie. How each candidate seed / location is evaluated is specified in the Candidate class.
References
Q Spaen, R Asín-Achá, SN Chettih, M Minderer, C Harvey, and DS Hochbaum (2019). HNCcorr: A Novel Combinatorial Approach for Cell Identification in Calcium-Imaging Movies. eNeuro, 6(2).
-
__init__
(seeder, postprocessor, segmentor, positive_seed_selector, negative_seed_selector, graph_constructor, candidate_class, patch_class, embedding_class, patch_size)[source]¶ Initalizes HNCcorr object.
-
classmethod
from_config
(config=None)[source]¶ Initializes HNCcorr from an HNCcorrConfig object.
Provides a simple way to initialize an HNCcorr object from a configuration. Default components are used, and parameters are taken from the input configuration or inferred from the default configuration if not specified.
- Parameters
config (HNCcorrConfig) – HNCcorrConfig object with modified configuration. Parameters that are not explicitly specified in the config object are taken from the default configuration
DEFAULT_CONFIGURATION
as defined in the hnccorr.config module.- Returns
Initialized HNCcorr object as parametrized by the configuration.
- Return type
-
segment
(movie)[source]¶ Applies the HNCcorr algorithm to identify cells in a calcium-imaging movie.
Identifies cells the spatial footprints of cells in a calcium imaging movie. Cells are identified based on a set of candidate locations identified by the seeder. If a cell is found, the pixels in the spatial footprint are excluded as seeds for future segmentations. This prevents that a cell is segmented more than once. Although segmented pixels cannot seed a new segmentation, they may be segmented again.
Identified cells are accessible through the segmentations attribute.
- Returns
Reference to itself.
-
segmentations_to_list
()[source]¶ Exports segmentations to a list of dictionaries.
Each dictionary in the list corresponds to the footprint of a cell. Each dictionary contains the key coordinates containing a list of pixel coordinates. Each pixel coordinate is a tuple with the zero-indexed coordinates of the pixel. Pixels are indexed like matrix coordinates.
- Returns
list[dict[tuple]]: List of cell coordinates.
-
-
class
hnccorr.base.
HNCcorrConfig
(**entries)[source]¶ Bases:
object
Configuration class for HNCcorr algorithm.
Enables tweaking the parameters of HNCcorr when used with the default components. Configurations are modular and can be combined using the addition operation.
Each parameter is accessible as an attribute when specified.
- Variables
seeder_mask_size (int) – Width in pixels of the region used by the seeder to compute the average correlation between a pixel and its neighbors.
seeder_exclusion_padding (int) – Distance for excluding additional pixels surrounding segmented cells.
seeder_grid_size (int) – Size of grid bloc per dimension. Seeder maintains only the best candidate pixel for each grid block.
percentage_of_seeds (float[0, 1]) – Fraction of candidate seeds to evaluate.
postprocessor_min_cell_size (int) – Lower bound on pixel count of a cell.
postprocessor_max_cell_size (int) – Upper bound on pixel count of a cell.
postprocessor_preferred_cell_size (int) – Pixel count of a typical cell.
positive_seed_radius (int) – Radius of the positive seed square / superpixel.
negative_seed_circle_radius (int) – Radius in pixels of the circle with negative seeds.
negative_seed_circle_count (int) – Number of negative seeds.
gaussian_similarity_alpha (alpha) – Decay factor in gaussian similarity function.
sparse_computation_grid_distance (float) – 1 / grid_resolution. Width of each block in sparse computation.
sparse_computation_dimension (int) – Dimension of the low-dimensional space in sparse computation.
patch_size (int) – Size in pixel of each dimension of the patch.
_entries (dict) – Dict with parameter keys and values. Each parameter value (when defined) is also accessible as an attribute.
-
__add__
(other)[source]¶ Combines two configurations and returns a new one.
If parameters are defined in both configurations, then other takes precedence.
- Parameters
other (HNCcorrConfig) – Another configuration object.
- Returns
Configuration with combined parameter sets.
- Return type
- Raises
TypeError – When other is not an instance of HNCcorrConfig.