Skip to main content
Advertisement
Browse Subject Areas
?

Click through the PLOS taxonomy to find articles in your field.

For more information about PLOS Subject Areas, click here.

  • Loading metrics

NeuronID: An automatic toolkit for identifying neurons in two-photon calcium imaging data

  • Jikan Peng,

    Roles Conceptualization, Data curation, Formal analysis, Investigation, Methodology, Project administration, Resources, Software, Validation, Visualization, Writing – original draft, Writing – review & editing

    Affiliations School of Medicine, Zhejiang University, Hangzhou, Zhejiang, China, Key Laboratory of Growth Regulation and Translation Research of Zhejiang Province, School of Life Sciences, Westlake University, Hangzhou, Zhejiang, China, Westlake Laboratory of Life Sciences and Biomedicine, Hangzhou, Zhejiang, China

  • Tian Xu

    Roles Conceptualization, Formal analysis, Funding acquisition, Investigation, Project administration, Resources, Supervision, Validation

    xutian@westlake.edu.cn

    Current address: School of Life Sciences, Westlake University, Hangzhou, Zhejiang, China

    Affiliations Key Laboratory of Growth Regulation and Translation Research of Zhejiang Province, School of Life Sciences, Westlake University, Hangzhou, Zhejiang, China, Westlake Laboratory of Life Sciences and Biomedicine, Hangzhou, Zhejiang, China

Abstract

Two-photon calcium imaging has emerged as a powerful technique for monitoring neuronal activity in neuroscience; however, its data processing remains challenging. Here, we introduce NeuronID, an automatic toolkit designed to process two-photon calcium imaging data. The NeuronID toolkit features a modular architecture that includes motion correction, noise reduction, segmentation of neuronal components, and extraction of neuronal signals. Notably, the NeuronID toolkit offers an optimized strategy for segmenting neuronal components, which systematically integrates morphological boundary identification, cross-correlation analysis between pixels, and evaluation of neuronal signal quality. Compared to existing tools or manual annotation by experts, the NeuronID toolkit reduces the likelihood of over-segmentation while achieving near-human accuracy. Overall, this study provides an effective solution to the segmentation of neuronal components, offering a standardized analytical tool for processing two-photon calcium imaging data.

Introduction

Monitoring single-neuron activity is essential for understanding the functional organization of the nervous system. Among available techniques for monitoring neuronal activity, two-photon calcium imaging has emerged as a powerful approach [1,2]. This approach detects neuronal activity by measuring changes in the fluorescence intensity of genetically encoded calcium indicators [37]. Two-photon calcium imaging has undergone substantial technological advancements, evolving from deep-tissue microscopy to high-speed volumetric imaging and miniaturized systems [1,2,810]. These developments now permit the recording of neuronal activity across entire brain regions in both head-fixed and freely moving animals. Importantly, the technique offers many advancements, including high-resolution visualization of neuronal morphology, precise anatomical mapping of single neurons, and detailed characterization of their spatiotemporal firing patterns over extended experimental periods.

However, as the scale and scope of two-photon calcium imaging continue to expand, the absence of standardized analytical tools has become a critical limitation. In particular, the accurate segmentation of neuronal components (e.g., soma), which is a fundamental step for converting raw imaging data into single-neuron activity, remains challenging, with existing methods often suffering from over-segmentation or suboptimal accuracy compared to manual annotation by experts [1113]. This prevalent issue of over-segmentation, wherein single neurons are erroneously split into multiple fragments, severely compromises downstream functional analysis. While manual annotation methods offer scalability, they often fail to reliably resolve this issue, creating a trade-off between throughput and accuracy.

To directly address this segmentation challenge, we introduce NeuronID, an open-source, automatic toolkit for processing two-photon calcium imaging data. The NeuronID toolkit employs an optimized segmentation strategy that is designed to systematically leverage both morphological and temporal information to segment neuronal components. This strategy minimizes over-segmentation errors encountered in existing methods while achieving accuracy comparable to manual annotation by experts.

Materials and methods

Two-photon datasets collection

In this study, we utilized six two-photon calcium imaging datasets from a previous study (Example Datasets 1–6, S1 Table) [14]. In these datasets, neuronal activity in layer II/III of the Posterior Parietal Cortex (PPC) was recorded in freely moving mice using FHIRM-TPM microscopy at a resolution of 600 × 512 pixels (487.80 × 416.20 μm) and a frame rate of 10 Hz for 60 minute. For validation, we used nine additional expert-annotated benchmark datasets from CaImAn (Example Datasets 7–15, S1 Table) [13]. Additionally, to further evaluate the performance of the NeuronID toolkit, we applied it to three two-photon calcium imaging datasets acquired from zebrafish (Example Dataset 16–18, S1 Table) [15].

Motion correction

In the NeuronID toolkit, we utilized the NoRMCorre algorithm to correct both rigid translations and non-rigid deformations in two-photon calcium imaging data [16]. To generate an initial reference template, we uniformly sampled 60 frames across the recording (one frame every 500 frames), ensuring coverage of diverse neural activity states. Notably, we implemented the latest Python version of NoRMCorre, while the original GitHub repository maintains only MATLAB code.

Noise reduction

In the NeuronID, we incorporated the DeepInterpolation algorithm to reduce noise in two-photon calcium imaging data [17]. This approach utilizes an encoder-decoder deep network architecture with skip connections, which reconstructs each target frame from its temporal context (30 preceding frames and 30 succeeding frame). Given that calcium indicator dynamics are scanning-frequency dependent, we provided multiple pre-trained DeepInterpolation networks optimized for different acquisition rates. For further customization, the NeuronID toolkit included a transfer learning module, enabling users to finetune models to their specific imaging conditions. By default, this module selects 360 representative frames (spaced at 100-frame intervals) and performs 10,000 training iterations, though these parameters remain user-adjustable. To ensure optimal performance, the NeuronID toolkit offers two key evaluation metrics: (1) reconstruction loss, calculated as the mean absolute difference in fluorescence intensity between original and reconstructed frames, and (2) pixel-wise signal-to-noise ratio (SNR), derived from the ratio of mean intensity to standard deviation for each pixel across all frames. A persistently high reconstruction loss or a low overall SNR suggests that the transfer learning may have failed to produce a high-quality model for the given data. We recommend that users discard the results under such circumstances and consider adjusting key parameters before re-running the transfer learning process.

Quantitative assessment of image quality

To quantitatively evaluate motion correction and noise reduction, we analyzed three key metrics on the mean projection images. Brightness was computed as the mean pixel intensity. Contrast was measured as the standard deviation of pixel intensities. Sharpness was quantified by calculating the standard deviation of the gradient magnitude across the image.

Segmentation of neuronal components

Step 1. ROI segmentation across periodic blocks.

In the NeuronID toolkit, we segmented neuronal components by first identifying potential regions of interest (ROIs) within distinct periodic blocks. By default, each periodic block comprises 100 sequential frames, with a 20-frame gap between adjacent blocks. For each periodic block, we converted all sequential frames into mean or max projection image. Specifically, the mean projection image was generated by calculating the average fluorescence intensity of individual pixels across all frames. The max projection image was generated by determining the highest fluorescence intensity of individual pixel across all frames. Additionally, the max-mean projection image was generated by comparing these two projection images. Subsequently, the max-mean projection image was normalized to scale the pixel intensities to a standardized range from 0 to 1. This crucial step ensures that the subsequent thresholding operation is applied consistently across all periodic blocks, eliminating biases that could arise from global intensity variations between different time segments. The normalized max-mean projection image was processed using an adaptive thresholding method, which determines the threshold for each pixel based on its local neighborhood mean to segment ROIs amid uneven illumination or artifacts [18]. The resulting ROIs were refined using morphological operations (closing enclosed voids) and an area filter (default diameter of 5 μm). Finally, each ROI in the resulting periodic masks was assigned a unique identifier, where all pixels belonging to the same ROI shared the same ID.

Step 2. ROI integration into a temporal mask.

Following ROI detection in periodic masks, we integrated them into a temporal mask. We first retained pixels detected as an ROI in at least three distinct blocks, classifying others as background. For each pixel retained after background segmentation, we constructed a feature vector comprising its spatial coordinates, the probability of being classified as an ROI, and the ID sequence across periodic masks. We reduced the dimensionality of these features using Principal Component Analysis (PCA), retaining 90 principal components (covering 95% variance) [19]. Next, we projected the reduced data into a 2D embedding space using t-SNE [20]. To group pixels, we applied K-means clustering to the t-SNE embedding, selecting 9,000 clusters based on the size and number of neuronal components [21]. Here, we classified the clusters into three types based on the spatial compactness of their constituent pixels in the original image coordinate space. This was quantified by calculating the maximum Euclidean distance between any two adjacent pixels in the 8-neighborhood connectivity graph within a cluster. Clusters were categorized as type 1 if this maximum distance was 1 pixel (immediate neighbors), type 2 if it was √2 pixels (diagonal neighbors), or type 3 if it exceeded √2 pixels. The cluster centers were designated as key pixels, with their 1,000 nearest neighbors in t-SNE space defining associated neighboring pixels. To quantity similarity between two pixels, we computed the Jaccard Index as the ratio of periodic masks where both pixels shared an ROI assignment to the total number of masks where either pixel was assigned to an ROI. Applying a JI threshold of 0.5 integrated the periodic masks into a final temporal mask.

Step 3. ROI Refinement into a spatial/soma mask.

We refined the temporal mask to produce the final soma mask by resolving overlaps and assessing signal quality. Where ROIs shared pixels, they were merged if more than 80% of their pixel pairs met the JI threshold of 0.5. ROI pairs failing this criterion were maintained as separate entities. This process yielded a spatial mask. Subsequently, the ROIs in this spatial mask were further refined based on their signal quality (as detailed in the following section), resulting in the final soma mask.

Refinement of fluorescence signal and identification of calcium transient

In the NeuronID toolkit, we implemented a gradient reduction algorithm to reduce neuropil contamination in ROI fluorescence signals [11,22]. The goal of this algorithm is to find an optimal scaling factor (ranging from 0 to 1) for the neuropil signal [11]. The algorithm operates iteratively, where every step involves subtracting a scaled version of the neuropil signal from the raw ROI signal and computing the resulting residual. The algorithm then adjusts the scaling factor to minimize the variance of this residual signal, under the principle that a properly corrected signal should exhibit minimal contamination from the surrounding neuropil. This process effectively isolates the neuron’s true fluorescence signal from the neuropil. Furthermore, we estimated and removed a polynomial trend from the fluorescence signal to account for photobleaching of calcium indicators, which is characterized by a gradual decline in fluorescence intensity over the course of imaging [6,23]. This polynomial trend was obtained by fitting a low-order polynomial to the long-term trend of the bleached signal. Subtracting this fitted polynomial restores a stable baseline, which is crucial for accurately detecting calcium transients and calculating ΔF/F. Additionally, we applied a 2σ threshold-based method to detect positive or negative transients in the calcium signal [24]. Specifically, positive transients were defined as increases in the calcium signal exceeding +2σ, where σ was calculated from the negative calcium signal; negative transients were defined as decreases exceeding −2σ, with σ derived from the positive calcium signal.

Comparative analysis

To evaluate the accuracy of the NeuronID toolkit, we compared its performance to CaImAn and Suite2p [12,13]. Notably, Suite2p was run using both its standard cell detection algorithm and the integrated Cellpose algorithm, while CaImAn was evaluated in both its BATCH and ONLINE processing modes [12,13,25]. We applied CaImAn (ONLINE) and Suite2p to Example Datasets 1–6 using their recommended default parameters. Since Suite2p (Cellpose) lacks a universal default setting, we employed a customized parameter set optimized for our data (S2 Table). Furthermore, to compare the performance of different cross-correlation strategies, we evaluated the method used by the NeuronID toolkit, which employs ID sequences across periodic blocks, against that of other toolkits, which rely on fluorescence signals across individual frames. Specifically, for each neuronal component identified by NeuronID, we computed the Pearson correlation coefficient (PCC) between pixels based on both their fluorescence signals across all frames and their ID sequences across blocks. Since these pixels originate from the same neuron, a higher PCC value indicates a stronger correlation and thus better performance of the method. Additionally, the overall segmentation accuracy of the three toolkits was benchmarked using the F1 score.

To further validate the NeuronID toolkit, we compared its performance with manual annotation by experts using Example Datasets 7–15 [13]. For these specific benchmark datasets, we directly utilized the pre-processing results and optimized parameters generated by the official CaImAn pipeline, ensuring a comparison against its best-performing, non-default state. The corresponding F1 scores for the Suite2p and CaImAn (ONLINR or Batch) tools on these nine datasets were sourced directly from the CaImAn study’s own benchmarking results [13]. Furthermore, each dataset was independently labeled by two to three experts, and consensus masks were used as the ground truth. We assessed the overlap between neuronal components identified by the NeuronID toolkit and those labeled by experts using the Intersection over Union (IoU), calculated as the area of overlap divided by the area of union for each pair of components. For each neuronal component labeled by experts, we calculated the IoU with each neuronal component segmented in the NeuronID toolkit, selecting the maximum value as the best match. The F1 score was then calculated based on a one-to-one matching between expert-labeled and NeuronID-segmented components. Specifically, a match was considered valid only if the IoU exceeded a threshold of 0.5. We then applied a greedy matching algorithm. This algorithm iteratively selected the expert-NeuronID pair with the highest IoU, recorded it as a true positive (TP), and removed both components from further consideration. The iteration continued until no remaining pairs had an IoU > 0.5. All unmatched NeuronID components were counted as false positives (FP), and all unmatched expert-labeled components were counted as false negatives (FN) [26]. From these values, we derived precision (TP/(TP + FP)), recall (TP/(TP + FN)), and the F1score (harmonic mean of precision and recall) (Table 1) [26].

Quantification and statistical analysis

In this study, we employed various statistical methods to analyze the data, including the paired t-test, the one-way ANOVA, and the Mann-Whitney U test. For comparisons involving multiple groups, one-way ANOVA was performed followed by post hoc Tukey’s test for detailed pairwise comparisons. For multiple paired t-tests, p-values were adjusted using the Holm-Bonferroni correction to control the family-wise error rate. P-values from the Mann-Whitney U test were adjusted using the Benjamini-Hochberg method. P-values were reported using scientific notation and rounded to two decimal places. In our data presentation, we utilized a variety of graphical representations to effectively convey our findings. Specifically, bar graphs were employed to illustrate mean values accompanied by Standard Error of the Mean (SEM) as error bars, with individual data points represented as dots for clarity (e.g., Fig 5D). Moreover, a specific graph was used to illustrate the distribution of the original data, presented through median values and interquartile ranges (e.g., Fig 2E).

thumbnail
Fig 1. Overview of the NeuronID toolkit and its preprocessing pipeline.

(A) The integrated workflow (top) and user-friendly graphical user interface (GUI, bottom) of the NeuronID toolkit. (B-C) Mean projection images before (B) and after (C) motion correction. (D-E) A typical frame before (D) and after (E) noise reduction. Scale bar: 30 μm (green) or 10 μm (blue).

https://doi.org/10.1371/journal.pone.0343516.g001

thumbnail
Fig 2. Asynchronous firing facilitates the segmentation of neuronal components.

(A) Three representative neuronal components at different frames and in the corresponding merged image. (B) An example of a periodic block, with the positions of two representative pixels indicated. (C, D) Fluorescence signals of two labeled pixels during the periodic block. (E) Distribution of the max-mean values of central pixels or boundary pixels within a given neuronal component. Mann–Whitney U test. (F) Example images of maximum projection, mean projection, and max-mean projection. (G) A representative periodic mask. Scale bar: 10 μm.

https://doi.org/10.1371/journal.pone.0343516.g002

thumbnail
Fig 3. Segmentation of background and neuronal components.

(A) Probability distribution for pixel classification into ROIs and segmentation of background (light green). (B) Four representative periodic masks with the positions of three selected pixels indicated. (C) ID sequences of the three pixels across periodic blocks. (D) t-SNE visualization of individual pixels, revealing 9,000 clusters identified by K-means clustering. (E) Distribution of the 9,000 clusters within the max-mean projection image. (F) Temporal mask. (G) Four representative ROIs repeatedly segmented. (H) Spatial mask. Scale bar: 30 μm in A and the left panels of E, F, and H; 10 μm in B and the right panels of E, F, and H.

https://doi.org/10.1371/journal.pone.0343516.g003

thumbnail
Fig 4. Extraction of neuronal signals.

(A) The illustration of a ROI (green) and its corresponding neuropil region (blue). Scale bar: 30 μm (green) or 10 μm (blue). (B) Fluorescence signals of the ROI (green) and the neuropil (blue) across individual frames. The black line indicates the 3σ level of the neuropil fluorescence signal. (C) Fluorescence signal of the ROI after neuropil contamination reduction and polynomial trend removal. The purple line represents the polynomial trend that was removed, illustrating the correction for photobleaching. (D) Distribution of fluorescence intensities, with the baseline indicated. (E) Calcium signal. (F) The calcium signal (dotted line) and the resulting event signal (solid line). (G) Event signal.

https://doi.org/10.1371/journal.pone.0343516.g004

Results

Overview of the NeuronID toolkit

The NeuronID toolkit is an automatic, modular pipeline for two-photon calcium imaging analysis, including motion correction, noise reduction, segmentation of neuronal components, and extraction of neuronal signals (Fig 1A). Particularly, the NeuronID toolkit integrates morphological boundary identification, cross-correlation analysis between pixels, and evaluation of neuronal signal quality to segment neuronal components (S1 Fig). It is important to note that the segmentation module in this release is specifically designed and validated for somatic signals. Furthermore, its adaptable design supports continuous integration of novel algorithms, and a MATLAB implementation is publicly available (https://github.com/Peng-Jikan/NeuronID). The toolkit is deployed as a standalone desktop application (APP) with an intuitive graphical user interface (GUI), greatly enhancing its accessibility for experimental researchers without programming expertise (Fig 1A).

Motion correction and noise reduction

Motion artifacts in two-photon calcium imaging data result from either rigid displacement or non-rigid deformations [27,28]. While multiple correction algorithms exist, we implemented the NoRMCorre algorithm in the NeuronID toolkit due to its proven efficacy and integration into widely used pipelines such as CaImAn (Methods) [13,16]. This algorithm successfully corrected both types of motion artifacts, as indicated by improved sharpness in mean projection images before and after procession (Figs 1B-C; S2A-B Figs). In addition, two-photon calcium imaging data is often contaminated by noise originating from electronic sources or the dynamics of calcium indicators [29]. To reduce this noise, we employed the DeepInterpolation algorithm, which utilizes an encoder-decoder deep network with skip connections to remove noise within each frame based on temporal context (Methods) [17]. This algorithm effectively reduced nearly all noise in individual frames (Figs 1D-E; S2C-D Figs).

Asynchronous firing gives rise to segmentation of neuronal components

In the NeuronID toolkit, we utilized asynchronous firing to segment neuronal components in two-photon calcium imaging data. First, we observed asynchronous firing across neurons, where only a subset of all recorded neurons was active in any given imaging frame (Fig 2A). This characteristic allowed us to identify distinct subsets of neuronal components across different time periods and then combine them to segment all neuronal components (Fig 2A). To implement this strategy, we divided the recording into temporally continuous periodic blocks (Fig 2B; Methods). Second, we discovered asynchronous firing between central pixels and boundary pixels within individual neurons. Specifically, central pixels maintained stable fluorescence signals during active periods, while boundary pixels exhibited transient intensity changes, leading to significantly greater max-mean intensity differences at boundary (Figs 2C, 2D and 2E). This characteristic allowed us to highlight the morphological boundaries of neuronal components in each periodic block by using the corresponding max-mean projection image (Fig 2F; Methods). To identify the morphological boundaries of neuronal components in each periodic block, we normalized the max-mean projection image and applied an adaptive threshold filter to generate periodic masks containing distinct regions of interest (ROIs) (Fig 2G). Subsequently, we refined the ROIs in the periodic masks using morphological operations (closing enclosed voids) and area criteria (by default, 5μm in diameter) (Fig 2G). Finally, each ROI in the periodic masks was assigned a unique identifier, with all pixels belonging to the same ROI sharing the same ID.

Cross-correlation analysis refines segmentation of neuronal components

As previous described, integrating ROIs across periodic masks is necessary to segment all neuronal components in two-photon calcium imaging data. To achieve this, we first retained pixels detected as an ROI in at least three distinct blocks, while classifying those with fewer occurrences as background, thereby excluding them from subsequent segmentation as they predominantly represent non-neuronal, neuropil signals (Fig 3A). We then grouped pixels sharing highly similar ID sequences with a Jaccard Index (JI) threshold of 0.5 (Figs 3B and 3C; Methods). However, performing cross-correlation analysis on all pixel pair imposed a substantial computational burden. For instance, in our example dataset, background segmentation left 280,338 pixels, resulting in over 39.3billion pixel pairs. To mitigate this, we identified 9,000 key representative pixels using an unsupervised clustering method and computed JI values only between these key pixels and their 1,000 neighboring pixels (Figs 3D and 3E; Methods). Consequently, we integrated periodic masks into a temporal mask (Fig 3F). In the temporal mask, we observed that some ROIs shared pixels, meaning the same physical pixel location was assigned to multiple ROIs. This phenomenon could result from either repeated segmentation of the same neuronal component or an overlapping field of view, where the somatic regions of two distinct neurons were in such close proximity that their 2D spatial projections overlapped in the imaging plane (Fig 3G). To address this, we merged any two overlapping ROIs if more than 80% of their pixel pairs met the JI threshold. ROI pairs failing to meet this merging criterion were maintained as separate entities. In these cases, the overlapping pixels were excluded from signal extraction for both ROIs to prevent signal cross-contamination. Finally, a spatial mask was derived from the temporal mask (Fig 3H).

Extraction of neuronal signals

For each ROI in the spatial mask, we first identified its constituent pixels and selected an equivalent number of surrounding background pixels as neuropil (Fig 4A). We then extracted the fluorescence signals of both the ROI and neuropil by calculating the mean fluorescence intensity of their respective pixels in each frame (Fig 4B). ROIs were retained if their fluorescence signals exceeded the 3σ level of their corresponding neuropil signals for at least three consecutive frames (Fig 4B). Next, we refined the ROI fluorescence signals by reducing neuropil contamination using a gradient reduction algorithm and removing photobleaching artifacts from the calcium indicators by eliminating polynomial trends in fluorescence decay over time (Fig 4C). Subsequently, we extracted the calcium signal of the ROI from the refined fluorescence signal using the ∆F/F metric, where ∆F represents the deviation from baseline fluorescence (F), estimated as the mode fluorescence intensity (Fig 4D). We further selected ROIs as neuronal components if they exhibited a ratio of positive-to-negative transients greater than ten (Methods) and removed the negative calcium signals to isolate calcium signal of the neuronal component (Fig 4E). Finally, we extracted event signal of the neuronal component by deconvolving its calcium signal using imaging parameters (100ms frame rate, 860ms decay constant of calcium indicator) and a 2σ threshold of the calcium signal (Fig 4F; Methods) [30]. The resulting positive signal within the event signal represented the firing status of the neuronal component, while the remaining signal represented the resting status (Fig 4G). This refined event signal can subsequently serve as a reliable basis for estimating spike timing or probability using algorithms appropriate for cognitive neuroscience analyses.

Accuracy of the NeuronID toolkit

Following the identification of morphological boundary, cross-correlation analysis between pixels, and evaluation of signals, the NeuronID toolkit successfully performed the segmentation of neuronal components, as illustrated in the soma mask (Fig 5A; S3A-C Figs; Methods). To evaluate its accuracy, we initially compared it against existing tools (CaImAn and Suite2p) on Example Datasets 1–6 [12,13]. First, we observed that some neuronal components were over-segmented in existing tools (Fig 5A and S4 Fig). We further observed that the morphological boundaries of some neuronal components were recognized more accurately in the NeuronID toolkit (Figs 5B and 5C). These observations indicated that the NeuronID toolkit effectively reduces over-segmentation. Indeed, the number of neuronal components segmented by the NeuronID toolkit was significantly fewer than that segmented by the two existing tools (Fig 5D; S3D Fig). To investigate the mechanism behind this improvement, we compared the temporal scales used for cross-correlation analysis. We found that cross-correlation analysis across periodic blocks yielded systematically higher pairwise pixel correlations (PCCs) within neuronal components than the frame-based correlation approach employed by other toolkits (Fig 5E).

To further evaluate the accuracy of the NeuronID toolkit, we compared it against manual annotation by experts using nine Example Datasets 7–15 [11,13]. First, we observed that segmentation of neuronal components using the NeuronID toolkit showed high concordance with manual annotation by experts (Fig 6A; S5 Fig). We further observed that the identification of morphological boundaries in some neuronal components approached the accuracy of manual annotation (Fig 6B). Our analysis revealed that approximately 80% of neuronal components were accurately segmented by the NeuronID toolkit, as measured by the Intersection over Union (IoU) (Fig 6C; Methods). The NeuronID toolkit achieved an average F1 score of 0.80, indicating near-human performance (Fig 6D; Table 1). Furthermore, this accuracy significantly surpassed that of existing toolkits on the same benchmark (Fig 6D; Table 1). Finally, to evaluate the performance of the NeuronID toolkit, we successfully applied it to two-photon calcium imaging datasets from zebrafish (S6 Fig). Together, these results established the NeuronID toolkit as a robust solution for reducing over-segmentation while maintaining high segmentation accuracy.

thumbnail
Fig 5. Comparative analysis of the NeuronID toolkit against two existing tools.

(A) Max-mean projection image (Raw) and soma masks generated by NeuronID, CaImAn (ONLINE), Suite2p, and Suite2p (Cellpose). Scale bar: 30 μm (left) or 10 μm (right). (B) Representative examples of somatic structures segmented by different toolkits. (C) Examples of complex neuronal components segmented by the three toolkits. (D) Number of neuronal components segmented by the three toolkits. N = 6. NeuronID: 342 ± 34 (Mean ± s.e.m.); CaImAn (ONLINE): 722 ± 25; Suite2p: 422 ± 57; Suite2p (Cellpose): 469 ± 41. Paired t-test. (E) Distribution of Pearson correlation coefficients (PCCs) between pixels within a given neuronal component across individual frames or periodic blocks. Mann-Whitney U test.

https://doi.org/10.1371/journal.pone.0343516.g005

thumbnail
Fig 6. Comparative analysis of the NeuronID toolkit versus manual annotation by experts.

(A) Max-mean projection image (Raw) and soma masks generated by manual annotation or the NeuronID toolkit. Scale bars: 30 μm (left) and 10 μm (right). (B) Representative examples of neuronal components segmented by both methods. (C) Distribution of the Intersection over Union (IoU) between a NeuronID-segmented neuronal component and its best-matching component from the expert manual annotation. 0: 2.52 ± 0.41%; 0-0.5: 14.32 ± 0.58%; 0.5-1: 83.16 ± 0.41%. N = 9. One-way ANOVA. (D) F1 score of different methods. Manual Annotation: 0.82 ± 0.02, N = 9; NeuronID: 0.80 ± 0.02, N = 9; CaImAn (ONLINE): 0.76 ± 0.01, N = 9; CaImAn (BATCH): 0.75 ± 0.01, N = 9; Suite2p: 0.58 ± 0.04, N = 8.

https://doi.org/10.1371/journal.pone.0343516.g006

Discussion

In this study, we introduced the NeuronID toolkit, which provides a standardized and automated pipeline for analyzing two-photon calcium imaging data. The NeuronID toolkit integrates four core modules, including motion correction, noise reduction, segmentation of neuronal components, and extraction of neuronal signals. Critically, the NeuronID toolkit is by design not restricted to a single model organism. While the present study has focused on its application in mouse, its successful preliminary application to zebrafish data also indicates promising potential for broader use. It would be intriguing to further apply and validate this toolkit across different species and experimental paradigms in future work.

Notably, the NeuronID toolkit offered a new strategy for segmenting neuronal components, which systematically combines morphological boundary identification, cross-correlation analysis between pixels, and evaluation of neuronal signal. In contrast, existing tools predominantly rely on cross-correlation analysis between pixels across individual frames to segment neuronal components [12,13]. Although these existing tools are computationally efficient and enable rapid processing, the frame-wise approach can be susceptible to transient noise and neuropil contamination, often resulting in over-segmentation, particularly in regions with high neuronal density or background activity. To address this, the NeuronID toolkit conducted the cross-correlation analysis between pixels across periodic blocks rather than across individual frames. This block-wise approach increased the likelihood of identifying pixels belonging to the same neuronal components, thereby reducing the likelihood of over-segmentation. Additionally, such reduction in over-segmentation could also result from the identification of morphological boundaries, which was not employed by existing tools. These comparative advantages position the NeuronID toolkit as a suitable tool for applications where precise segmentation of neuronal components is paramount. Users should consider these advantages alongside the toolkit’s limitations, detailed in the following section, when selecting an analysis method for their specific experimental needs.

In addition to the reduction of over-segmentation, the NeuronID toolkit achieves accuracy comparable to that of human experts. While manual annotation by experts serves as a ground truth, its practical utility is limited by inter-observer variability and the scarcity of such expertise in most laboratories. In contrast, the NeuronID toolkit not only achieves near-human accuracy but also delivers standardized, reproducible segmentation for any given dataset. Together, these features establish the NeuronID toolkit as an effective solution for neuronal segmentation. Although the current segmentation strategy is specifically designed for two-photon calcium imaging, the core principle of leveraging asynchronous firing among different neurons or within a given neuron, could inspire new approaches for segmenting structures in other biological imaging datasets.

Limitation of the NeuronID toolkit

The current version of NeuronID is specifically designed for two-photon calcium imaging data capturing the somatic structures of hundreds of neurons. A key premise of our segmentation strategy is the exploitation of asynchronous neuronal activity to distinguish individual cells. Consequently, the toolkit may be less effective for populations of neurons that fire with a high degree of synchrony, where temporal correlation profiles become indistinguishable. Additionally, the computational processing speed of NeuronID may be a limiting factor for very large datasets, such as those involving continuous multi-day recordings. Furthermore, future developments should aim to extend its capabilities to process complex subcellular structures (e.g., axons, dendrites, and synapses) as well as to handle volumetric data [3134]. The modular architecture of the NeuronID toolkit is intentionally designed to support future enhancements and adaptability.

Supporting information

S1 Table. The information of example datasets.

https://doi.org/10.1371/journal.pone.0343516.s001

(DOCX)

S1 Fig. The workflow of segmentation of neuronal components in the NeuronID toolkit.

The schematic illustrates the key stages of the automated segmentation pipeline: (1) Detection of periodic masks via identification of morphological ROI boundaries; (2) Integration of periodic masks into a temporal mask through cross-correlation analysis; (3) Refinement into a spatial mask by resolving overlapping ROIs; (4) Generation of the final soma mask based on signal quality criteria.

https://doi.org/10.1371/journal.pone.0343516.s003

(TIF)

S2 Fig. Quantitative assessment of motion correction and noise reduction.

(A, B) Comparison of brightness (A) and sharpness (B) between the mean projections of the raw and motion-corrected frame stacks. (C, D) Comparison of contrast (C) and the single-pixel signal-to-noise ratio (SNR) (D) between the original and denoised frame stacks. In A-D, two-tailed paired t-test.

https://doi.org/10.1371/journal.pone.0343516.s004

(TIF)

S3 Fig. Supplementary analyses of the segmentation workflow and outcomes.

(A) The accumulative curves of probability for a pixel being detected as part of an ROI, for pixels within final neuronal components (black line) or pixels outside neuronal components (gray line). (B) The percentage of three types of clusters among the 9,000 clusters identified via unsupervised clustering (Methods). N = 6. Type 1: 55.90 ± 1.83%; Type 2: 15.83 ± 0.38%; Type 3: 28.27 ± 1.47%. (C) The distribution of the final, consolidated ROIs from the soma mask projected back into the t-SNE embedding space. The emergence of larger, unified color patches, compared to the initial pixel-level clusters in Figure 3D, visually demonstrates the effective reduction of over-segmentation. (D) Comparison of the segmentation accuracy (F1 score) among the NeuronID toolkit, CaImAn (ONLINE), Suite2p, and Suite2p (Cellpose).

https://doi.org/10.1371/journal.pone.0343516.s005

(TIF)

S4 Fig. Comparative analysis among three toolkits.

The max-mean projection images (Raw) and soma masks generated by NeuronID, CaImAn (ONLINE), Suite2p, and Suite2p (Cellpose) across five example datasets. Scale bar: 30 μm.

https://doi.org/10.1371/journal.pone.0343516.s006

(TIF)

S5 Fig. Comparative analysis of the NeuronID toolkit versus manual annotation.

Max-mean projection images (Raw) and soma masks generated by the human annotation or the NeuronID toolkit. Scale bar: 30 μm.

https://doi.org/10.1371/journal.pone.0343516.s007

(TIF)

S6 Fig. Cross-species implementation of the NeuronID toolkit.

The toolkit successfully processes two-photon calcium imaging datasets from zebrafish, as shown by the mean projection images (Raw) and soma masks (NeuronID). Scale bar: 10 μm.

https://doi.org/10.1371/journal.pone.0343516.s008

(TIF)

Acknowledgments

We thank Hongyan Yang for technical assistance and Xu lab members for discussion. JKP are supported by Westlake University Predoctoral Fellowship. TX is grateful to Yale and HHMI for more than two decades of support.

References

  1. 1. Denk W, Strickler JH, Webb WW. Two-photon laser scanning fluorescence microscopy. Science. 1990;248(4951):73–6. pmid:2321027
  2. 2. Grienberger C, Giovannucci A, Zeiger W, Portera-Cailliau C. Two-photon calcium imaging of neuronal activity. Nat Rev Methods Primers. 2022;2(1):67. pmid:38124998
  3. 3. Chen T-W, Wardill TJ, Sun Y, Pulver SR, Renninger SL, Baohan A, et al. Ultrasensitive fluorescent proteins for imaging neuronal activity. Nature. 2013;499(7458):295–300. pmid:23868258
  4. 4. Tian L, Hires SA, Mao T, Huber D, Chiappe ME, Chalasani SH, et al. Imaging neural activity in worms, flies and mice with improved GCaMP calcium indicators. Nat Methods. 2009;6(12):875–81. pmid:19898485
  5. 5. Inoue M. Genetically encoded calcium indicators to probe complex brain circuit dynamics in vivo. Neurosci Res. 2021;169:2–8. pmid:32531233
  6. 6. Miyawaki A, Llopis J, Heim R, McCaffery JM, Adams JA, Ikura M, et al. Fluorescent indicators for Ca2+ based on green fluorescent proteins and calmodulin. Nature. 1997;388(6645):882–7. pmid:9278050
  7. 7. Nakai J, Ohkura M, Imoto K. A high signal-to-noise Ca(2+) probe composed of a single green fluorescent protein. Nat Biotechnol. 2001;19(2):137–41. pmid:11175727
  8. 8. Zong W, Wu R, Li M, Hu Y, Li Y, Li J, et al. Fast high-resolution miniature two-photon microscopy for brain imaging in freely behaving mice. Nat Methods. 2017;14(7):713–9. pmid:28553965
  9. 9. Sofroniew NJ, Flickinger D, King J, Svoboda K. A large field of view two-photon mesoscope with subcellular resolution for in vivo imaging. Elife. 2016;5:e14472. pmid:27300105
  10. 10. Helmchen F, Denk W. Deep tissue two-photon microscopy. Nat Methods. 2005;2(12):932–40. pmid:16299478
  11. 11. de Vries SEJ, Lecoq JA, Buice MA, Groblewski PA, Ocker GK, Oliver M, et al. A large-scale standardized physiological survey reveals functional organization of the mouse visual cortex. Nat Neurosci. 2020;23(1):138–51. pmid:31844315
  12. 12. Pachitariu M, Stringer C, Dipoppa M, Schröder S, Rossi F, Dalgleish H, et al. Suite2p: beyond 10,000 neurons with standard two-photon microscopy. bioRxiv. 2016.
  13. 13. Giovannucci A, Friedrich J, Gunn P, Kalfon J, Brown BL, Koay SA, et al. CaImAn an open source tool for scalable calcium imaging data analysis. Elife. 2019;8:e38173. pmid:30652683
  14. 14. Peng J, Yang D, Xu C, Xu T. Population coding of quantity discrimination in mouse posterior parietal cortex. openRxiv. 2025.
  15. 15. Eom M, Han S, Park P, Kim G, Cho E-S, Sim J, et al. Statistically unbiased prediction enables accurate denoising of voltage imaging data. Nat Methods. 2023;20(10):1581–92. pmid:37723246
  16. 16. Pnevmatikakis EA, Giovannucci A. NoRMCorre: An online algorithm for piecewise rigid motion correction of calcium imaging data. J Neurosci Methods. 2017;291:83–94. pmid:28782629
  17. 17. Lecoq J, Oliver M, Siegle JH, Orlova N, Ledochowitsch P, Koch C. Removing independent noise in systems neuroscience data using DeepInterpolation. Nat Methods. 2021;18(11):1401–8. pmid:34650233
  18. 18. Bradley D, Roth G. Adaptive Thresholding using the Integral Image. Journal of Graphics Tools. 2007;12(2):13–21.
  19. 19. KP 1 9 F R S. On lines and planes of closest fit to systems of points in space. Philosophical Magazine Series 1. 1901;2:559–72.
  20. 20. van der Maaten L, Hinton G. Visualizing data using t-SNE. Journal of Machine Learning Research. 2008;9:2579–605.
  21. 21. Macqueen JJPSMS, Probability t. Some methods for classification and analysis of multivariate observations. Proceedings of the 5th Berkeley Symposium on Mathematical Statistics and Probability. 1967;1.
  22. 22. Pascanu R, Mikolov T, Bengio Y. On the difficulty of training recurrent neural networks. In: 2013. 1310–8.
  23. 23. Scheenen WJ, Makings LR, Gross LR, Pozzan T, Tsien RY. Photodegradation of indo-1 and its effect on apparent Ca2+ concentrations. Chem Biol. 1996;3(9):765–74. pmid:8939693
  24. 24. Komiyama T, Sato TR, O’Connor DH, Zhang Y-X, Huber D, Hooks BM, et al. Learning-related fine-scale specificity imaged in motor cortex circuits of behaving mice. Nature. 2010;464(7292):1182–6. pmid:20376005
  25. 25. Stringer C, Wang T, Michaelos M, Pachitariu M. Cellpose: a generalist algorithm for cellular segmentation. Nat Methods. 2021;18(1):100–6. pmid:33318659
  26. 26. Christen P, Hand DJ, Kirielle N. A Review of the F-Measure: Its History, Properties, Criticism, and Alternatives. ACM Comput Surv. 2023;56(3):1–24.
  27. 27. Shipley FB, Dani N, Xu H, Deister C, Cui J, Head JP, et al. Tracking Calcium Dynamics and Immune Surveillance at the Choroid Plexus Blood-Cerebrospinal Fluid Interface. Neuron. 2020;108(4):623-639.e10. pmid:32961128
  28. 28. Dombeck DA, Khabbaz AN, Collman F, Adelman TL, Tank DW. Imaging large-scale neural activity with cellular resolution in awake, mobile mice. Neuron. 2007;56(1):43–57. pmid:17920014
  29. 29. Malik WQ, Schummers J, Sur M, Brown EN. Denoising two-photon calcium imaging data. PLoS One. 2011;6(6):e20490. pmid:21687727
  30. 30. Kerr JND, Greenberg D, Helmchen F. Imaging input and output of neocortical networks in vivo. Proc Natl Acad Sci U S A. 2005;102(39):14063–8. pmid:16157876
  31. 31. Demas J, Manley J, Tejera F, Barber K, Kim H, Traub FM, et al. High-speed, cortex-wide volumetric recording of neuroactivity at cellular resolution using light beads microscopy. Nat Methods. 2021;18(9):1103–11. pmid:34462592
  32. 32. Park E-Y, Cai X, Foiret J, Bendjador H, Hyun D, Fite BZ, et al. Fast volumetric ultrasound facilitates high-resolution 3D mapping of tissue compartments. Sci Adv. 2023;9(22):eadg8176. pmid:37256942
  33. 33. Sadakane O, Masamizu Y, Watakabe A, Terada S-I, Ohtsuka M, Takaji M, et al. Long-Term Two-Photon Calcium Imaging of Neuronal Populations with Subcellular Resolution in Adult Non-human Primates. Cell Rep. 2015;13(9):1989–99. pmid:26655910
  34. 34. Broussard GJ, Liang Y, Fridman M, Unger EK, Meng G, Xiao X, et al. In vivo measurement of afferent activity with axon-specific calcium imaging. Nat Neurosci. 2018;21(9):1272–80. pmid:30127424