Introduction

In order to understand how complex cellular systems operate and interact with each other, it is essential to be able to record activity from many individual cells simultaneously. Fluorescent calcium (Ca2+) imaging, either with small organic Ca2+ indicators or with genetically encoded Ca2+ indicators (GECI)1,2, is a widely used method to study large amounts of cells simultaneously and examine their network activity. Since cytosolic Ca2+ changes are tightly linked to action potential firing (and thus activity) in excitable cells like neurons, this imaging technique allows inferring neuronal activity of a large cellular population in both the central and peripheral nervous systems3. Recent improvements in Ca2+ indicator quality (higher quantum efficiency and therefore better signal to noise) and imaging technologies allow monitoring larger populations of neurons at higher spatiotemporal resolution4,5. As a result, Ca2+ imaging became a powerful tool that provides unique insights in physiological behavior of cells and tissues. The power of the method is in the fact that the focus of analysis can be at the individual cell level as well as on the network of interacting cells. As such it allows studying and understanding communication between cooperating functional groups of neurons (or other cells) at a high spatiotemporal resolution6,7,8.

An extra complexity with live imaging of cells is that they may not be stationary in the microscopic field of view, either because they traffic themselves or the tissue, in which they are embedded, is contractile. Recordings in the central nervous system and acute brain slices can be assumed to have static scenes where the only movements present are motion artifacts such as drift, as in brain slices, or cyclic movements, as induced by breathing in intravital recordings. However, recording activity from tissues with a predominantly contractile function, such as the heart or the intestine, or from in vivo imaging of awake animals (zebrafish, C. elegans, etc.) presents unique challenges due to the drastically high level of movement caused by muscle contractions.

In the intestine, all motor activity is controlled by a continuous network of neurons and glia cells embedded in between two concentric muscle layers. This enteric nervous system (ENS) regulates gut functions such as motility, secretion, and absorption6,9. To understand how the complex circuits in the ENS operate to produce functional output, it is necessary to record and analyze the activity of large populations of ENS cells. Ca2+ imaging is the optimal tool to achieve this goal. However, the extraction of Ca2+ signals from these recordings is an important bottleneck in the analysis workflow. As a result, a compromise is needed, in which the tissues are prepared (by removing muscle layers that are innervated by the ENS) or treated (by adding pharmacological compounds), to limit movement in these recordings and as such facilitate signal extraction3,10. In order to derive physiological information from the tissues in their most intact state, an alternative method for analysis is required.

A traditional analysis workflow in Ca2+ imaging starts with image registration of the recorded frames to correct for motion artifacts and slight underlying movements aiming to attain a completely static scene where each pixel represents the same physical location throughout all frames11. This step, if successful, is followed by signal extraction, where the different cells of interest are delineated and their pixel intensity profiles are extracted. For the large majority of Ca2+ imaging experiments, this workflow is sufficient to efficiently analyze cellular activity profiles and has been used extensively in ENS Ca2+ imaging provided that contractions are restrained either pharmacologically, physically, or in combination12,13.

Multiple different software packages have been developed to automate the signal extraction process and efficiently analyze the ever-longer recordings and ever-increasing Ca2+ imaging datasets14,15. However, these automated analysis workflows also rely on an image registration step and assume that all objects in the image are spatially static after this step, in order to extract their signals. Contractile movements, as those in the intestine, can include complex deformations that cannot be compensated with rigid registration techniques. More advanced non-rigid registration techniques, which offer registration with a high degree of freedom to accommodate more complex deformations, can be used but they are susceptible to high noise levels and artifacts, two regularly occurring problems in Ca2+ imaging. The tight packing of neurons in small groups (ganglia), with their apparent overlap in optical recordings (Fig. 1A), is a first challenge that eliminates the use of classic segmentation workflows. Moreover, the rapidly oscillating fluorescence of active neurons in Ca2+ imaging (Fig. 1B) has a negative impact on the success rate of registration algorithms as these rely on pixel intensity or image feature matching and thus have endogenous problems with changes in intensity12,16,17. ENS Ca2+ imaging combines the aforementioned challenges (Fig. 1C) and thus urges the development of an alternative analysis workflow to delineate and track individual cells in moving tissues, and extract their signals throughout the recordings.

Figure 1
figure 1

General features of Ca2+ imaging in the ENS. (A) The appearance of an individual GCaMP expressing enteric neuron when not surrounded by other neurons (Left). The overlapping appearance of enteric neurons (arrow) and lack of clear borders (arrowhead) (Right). Scale bar represents 50 µm. (B) an example of the fluorescence signal increases between a neuron at rest (left, and marked with a dashed line) and during activity (right). C) ENS ganglion (left) containing approximately 20 neurons. Imposed images of different timepoint (colorcoded in green and magenta) in an ENS Ca2+ recording (1 s. interval between frames). The mismatch in colors indicates the amount of movement that can be present between 2 frames.

A viable alternative to registration in these complex scenarios is cell tracking. While tracking techniques have been extensively used in cell migration analysis and lineage tree construction18,19,20, the low level-based segmentation techniques20,21 that are normally used in these applications perform poorly in ENS recordings since they are prone to noise, variability in the edge intensity due to overlap, and cannot adapt to the blinking cell appearance between different frames22. The existing region-based tracking techniques are not sufficient to segment complex structures based on their texture information23,24. Moreover, they are ineffective when dealing with nonhomogeneous and overlapping objects, such as cells with bright cytoplasm and dark nuclei (Fig. 1A) as is the case with the expression of the common Ca2+ indicator GCaMP. Only one report, by Hennig et. al.25 was published, in which nucleus tracking of ENS neurons was used, by means of edge detection where dark nuclei were identified and segmented in each frame to extract fluorescent GCaMP signals from their surrounding pixels. Practically, manual region-of-interest (ROI) selection remains the most commonly used approach to analyze ENS recordings, at least for those in which motion can be easily corrected. Recordings that rigid registration cannot stabilize are routinely disregarded.

Due to its ease of application and flexibility in handling cell division, the main method used in the cell tracking field is segmentation, based on implicit functions such as level-sets26,27,28. However, the large flexibility in this implicit topological representation can easily produce incorrect results29 especially in low signal to noise ratio (SNR) recordings. In these situations, explicit functions such as explicit active contours30 perform better as they depend on parameters and therefore their evolution is more restricted and faster to calculate31. The main disadvantage of explicit active surfaces is the inability in handling cell division, which is not relevant in the specific context of tracking neurons21. In this paper, we implement B-spline-Explicit Active Surfaces (BEAS) as developed by Barbosa et. al.32 which allows the application of local and global region-based energy terms in segmentation, as originally developed for level-set segmentation33, while controlling contour smoothness and keeping the computational cost low32,34. This method is suitable to segment heterogeneous objects (such as cells with dark nuclei, with varying degrees of brightness and edge clarity, Fig. 1B) and to apply multiple local and global energy terms to reach that goal.

In this paper, we use the BEAS framework on 2D microscopy recordings to track and analyze multiple cells within a contractile and moving ENS tissue. Apart from employing multiple global and local energy terms to direct contour evolution, we also use a competition penalty to limit and manage overlap between neighboring cells. Furthermore, we develop ‘double contour (DC)’ tracking, a novel method that couples the development of two contour layers and takes advantage of the typical appearance of GCaMP expressing cells. Due to the nuclear exclusion of GCaMP, these cells present in Ca2+ imaging recordings with a dark nucleus and a bright cytoplasm, the edges of which are respectively tracked by the two layers. This DC method enables accurate cell tracking even in the absence of visible external borders. We describe the elements in the Ca2+ imaging and cell tracking algorithm developed and make this information freely available for external use.

In conclusion, we aimed to develop a set of techniques to better extract cellular activity levels from Ca2+ imaging recordings of non-static moving cells (Fig. 2). To this end, we used the ENS as a model system harboring fairly complex movement and activity-dependent intensity changes. The resulting workflow is however flexible and can be used to analyze other cellular recordings by tweaking the contour parameters to match the specific application.

Figure 2
figure 2

(A) diagram of the processing workflow including the main steps of cell tracking (Blue) and the optional ROI tracking (grey). (B) Example of the performance of the cell tracking procedure of multiple cells in ENS recordings, using one-layer tracking (left) and double contours (right).

Methodology

The workflow for the proposed cell tracking approach starts by drawing an ellipse around the cell to initialize the contour. This step is followed by deforming the contour iteratively by applying forces on individual contour control points until the functional energy minimum is reached as an initial segmentation step, which theoretically overlays the contour with the cell’s boundary. The initialization is followed by the cell tracking loop, which consists of a series of consequent segmentation tasks on individual frames, where each contour in a frame is used to initialize the contour’s segmentation on the following frame. During an intermediate step, parametric information about the contour is calculated and the contour center is also recalculated to be in the geometric centroid of the produced contour shape to ensure that the new center is inside the cell in each next frame, even if there was movement between frames (Suppl. Fig. 1). By stringing the segmentation results together, we acquire both the location of individual cells as well as their contours throughout the entire recording (Fig. 2B).

The goal of this approach is to use these dynamic contours as regions-of-interest (ROIs) from which the mean intensity signal is extracted to accurately represent Ca2+ activity of cells in a non-static setting. These contours are then evaluated by the user. Furthermore, the tracked cell locations can also be used as landmarks to optionally track or displace additional and manually created ROIs, in cases where a tracked cell’s contour was not satisfactory or when tracking additional ROIs posthoc is desired (Fig. 2A).

B-Spline Explicit Active contours algorithm (BEAS)

We implement the B-Spline Explicit Active Surfaces (BEAS)35 framework developed and optimized for segmenting and tracking heart chambers in echocardiography34,35,36. The method uses an explicit function to represent the boundary of an object, where coordinates of the contour points are explicitly given as a function of the remaining coordinates i.e.,\({ }x_{1} = \psi \left( {x_{2} , \ldots ,x_{n} } \right)\) where \(\psi\) is defined as a linear combination of B-spline basis functions

$$ \begin{array}{*{20}c} {x_{1} = \psi \left( {x_{2} , \ldots ,x_{n} } \right) = \psi \left( {{\mathbf{x}}^{*} } \right) = \mathop \sum \limits_{{{\mathbf{k}} \in {\mathbb{Z}}^{n - 1} }} {\text{c}}\left[ {\mathbf{k}} \right]\beta^{d} \left( {\frac{{{\mathbf{x}}^{*} }}{h} - {\mathbf{k}}} \right)} \\ \end{array} $$
(1)

where \(\beta^{d} \left( . \right)\) is the uniform symmetric B-spline of degree d. The knots of the B-splines are located on a rectangular grid, with a regular spacing given by h. The coefficients of the B-spline representation are gathered in c[k]. For this 2D segmentation problem, a polar coordinate system was chosen.

The evolution of the contour is governed by the minimization of the energy term E. This energy has two elements, the image data term Ed and an internal energy Er.

$$ \begin{array}{*{20}c} {E = E_{d} + E_{r} } \\ \end{array} $$
(2)

Data attachment

One-layer contour

The data attachment energy term in Eq. 2 can be defined, following the BEAS formulation, as:

$$ E_{d} = { }\mathop \smallint \limits_{{\Omega }} \delta_{{\phi_{{{\text{cyt}}}} }} \left( {\mathbf{x}} \right)\mathop \smallint \limits_{{\Omega }} B\left( {{\mathbf{x}},{\mathbf{y}}} \right) \cdot F_{{{\text{cyt}}}} \left( {\mathbf{y}} \right)d{\mathbf{y}}d{\mathbf{x}} $$
(3)

where \(F_{{{\text{cyt}}}} \left( {\mathbf{y}} \right)\) is the energy criterion driving the evolution of the contour and \(B\left( {{\mathbf{x}},{\mathbf{y}}} \right)\) is a mask function in which the local parameters that drive the evolution are estimated. \(\delta_{{\phi_{{{\text{cyt}}}} }} \left( {\mathbf{x}} \right)\) is the Dirac operator applied to the level set function \(\phi \left( {\mathbf{x}} \right) = {\Gamma }\left( {{\mathbf{x}}^{\user2{*}} } \right) - x_{1}\) which is defined over the image domain Ω. The mask function \(B\left( {{\mathbf{x}},{\mathbf{y}}} \right)\) for a node (neighborhood radius) is specified as a column of pixels of length ρ in the normal direction centered around a contour node. The value of ρ is chosen a priori, based on the expected margin (frontier) size between objects and the rate of movement between frames. When segmenting GCaMP expressing cells, it is logical to set this parameter to be slightly smaller than the approximate radius of cells, to avoid detecting the cytoplasm-nucleus edge instead of the intracellular interface. The degree of visibility of a cell’s border in Ca2+ imaging is quite variable as its strength is based on the Ca2+ concentration inside the cell of interest as well as that of adjacent cells. Moreover, the imaging conditions and imaging system chosen also impact the cell’s appearance (Fig. 1A). Therefore, we chose a flexible localized energy term introduced by Yezzi et al.37 (Eq. 4), to maximize the difference of mean intensity inside and outside each contour node.

$$ \begin{array}{*{20}c} {F_{{{\text{cyt}}}} = - (u_{{{\text{cyt}}}} - u_{{{\text{out}}}} )^{2} } \\ \end{array} $$
(4)

where \(u_{{{\text{cyt}}}}\) and \(u_{{{\text{out}}}}\) are the mean intensity values in the cytosolic region (inside the cell) and the region outside of the cell, respectively.

Double contour

In live fluorescent imaging (eg. in Ca2+ imaging), the interface between the bright cytoplasm, which can be dim if intracellular Ca2+ concentrations are low, and the heterogeneous background may lack contrast and as such limit cell tracking capability. GCaMP expressing cells have a bright cell body and a dark nucleus because the GCaMP molecule molecules do not enter the nucleus. Therefore, a second, and often sharper interface, between the dark nucleus and the bright cytoplasm emerges. This interface is stable and has a predictable (dark) inner side and (bright) outer side. Therefore, we developed a coupled two-layer active contour segmentation of cells. The two layers delineate the nucleus-cytoplasm and the cytoplasm-background interfaces, respectively. The inner layer \(\phi_{{{\text{nuc}}}} \) is delineating the stable shape of the nucleus while the outer contour \(\phi_{{{\text{cyt}}}}\) attempts to delineate cell outer borders forming a “double contour”. The image-data energy term in Eq. 2 can instead be defined as:

$$ E_{d} = \mathop \smallint \limits_{{\Omega }} \delta_{{\phi_{{{\text{nuc}}}} }} \left( {\mathbf{x}} \right)\mathop \smallint \limits_{{\Omega }} B\left( {{\mathbf{x}},{\mathbf{y}}} \right) \cdot F_{{{\text{nuc}}}} \left( {\mathbf{y}} \right)d{\mathbf{y}}d{\mathbf{x}} + \mathop \smallint \limits_{{\Omega }} \delta_{{\phi_{{{\text{cyt}}}} }} \left( {\mathbf{x}} \right)\mathop \smallint \limits_{{\Omega }} B\left( {{\mathbf{x}},{\mathbf{y}}} \right) \cdot F_{{{\text{cyt}}}} \left( {\mathbf{y}} \right)d{\mathbf{y}}d{\mathbf{x}} $$
(5)

with \(F_{{{\text{nuc}}}}\) following \(F_{{{\text{cyt}}}}\) in its definition (Eq. 4). The double contour produces a more stable contour progression and keeps the contour attracted to cells in the event of non-visible cellular borders (Fig. 3). It also allows the extraction of the signal that originates from the cytoplasm pixels only, which improves the signal to noise ratios of the extracted mean fluorescence.

Figure 3
figure 3

The effect of a competition term on neighboring contours (top) The contour of a cell using 1-layer vs double contour in a GCaMP expressing neuron (bottom).

Data regularization

The energy term Er in Eq. (2) relates to curvature, size, and size difference compared to the previous frame. We use prior knowledge about the properties of ENS neurons to impose local and global penalties to guide the contours and ensure that segmentation results and contour shapes will be plausible in their curvature, size, and size differential between timesteps. The regularization term Er is defined as:

$$ \begin{array}{*{20}c} {E_{r} = w_{\kappa } E_{\kappa } { } + { }w_{A} E_{A} + { }w_{AS} E_{AS} } \\ \end{array} $$
(6)

The curvature energy term Eκ limits the negative local mean curvature since cell bodies mostly have positive curvature. The local curvature gradient term is given by:

$$ \begin{array}{*{20}c} {\frac{{\partial E_{\kappa } }}{{\partial c_{{W_{P} }} \left[ {{\mathbf{k}}_{i} } \right]}} = \mathop \smallint \limits_{{\Gamma }} \kappa \left( {{\mathbf{x}}^{*} } \right)H\left( { - \kappa \left( {{\mathbf{x}}^{*} } \right)} \right)\beta^{d} \left( {\frac{{{\mathbf{x}}^{*} }}{h} - {\mathbf{k}}_{i} } \right)d{\mathbf{x}}^{*} } \\ \end{array} $$
(7)

where \(\kappa\) is the local mean curvature which is calculated efficiently as reported within the BEAS framework34,38 and H is the Heaviside function.

The area energy term EA keeps the size of the contour within a reasonable range, where A represents the area within the contour. The parameters Amin and AMax ensure that the contour does not engulf bigger image regions. The equation for local energy calculation is governed by:

$$ \frac{{\partial E_{A} }}{{\partial c_{{W_{A} }} \left[ {{\mathbf{k}}_{i} } \right]}} = \left( {A - A_{Min} } \right)H\left( {A_{Min} - {\text{A}}} \right){ } + \left( {A_{Max} - {\text{A}}} \right)H\left( {{\text{A}} - A_{Max} } \right) $$
(8)

Next, we add the area stability energy term EAS, which is a global energy term that attempts to minimize the change of the area within the contour keeping its size in a reasonable range for a cell, since apparent size changes are not real but are due to intensity variations or edge contrast changes and not caused by actual cell size changes.

$$ E_{AS} =\frac{\| {A_{t} - A_{t - 1}\| }}{{A_{t - 1} }} $$
(9)

The weights \(w_{\kappa }\), \(w_{A}\) and \(w_{AS}\) in Eq. (6) are chosen by the user based on the morphology and size of the cells in the image.

Contour competition

It is common for cells in microscopy recordings to appear overlapping, as an image is a projection of all fluorescent elements in the focus of the objective lens. Especially in widefield microscopy recordings where images result from many different in- and out-of-focus planes39. This effect is minimized in confocal and multiphoton excitation approaches, but optical overlap remains an issue due to limited optical resolution. While banning overlap completely can facilitate interpretation of the extracted data, it does not represent the scene correctly and can lead to tracking errors. Therefore, we impose a competition penalty that allows a slight contour overlap to account for the optical overlapping effect while preventing contours from jumping between cells or engulfing multiple cells. We opted to impose a proximity penalty between neighboring contour nodes, as implemented previously in BEAS40, to limit contour expansion into neighboring contours and reduce overlap (\(E^{dist}\)),

$$ E_{i \to j}^{dist} \begin{array}{*{20}c} {\left( {{\varvec{x}}^{*} } \right) = \left( {d_{T} - {\varvec{\psi}}^{i \to j} } \right).H\left( {d_{T} - {\varvec{\psi}}^{i \to j} } \right)} \\ \end{array} $$
(10)

where \({ }d_{thresh}\) represents the minimal distance parameter, ψ is a signed distance map between each node of the contour i against all nodes of contour j (and vice-versa), and H is the Heaviside operator. Note that H equals one only in nodes with ψ lower than \({ }d_{thresh} \) and zero in the remaining nodes. Therefore, it only applies penalties in the neighboring regions of the contours40.

We also added a stronger penalty for actual overlap on both contours (\(E_{overlap}\)) producing a cell competition effect controlled by the cell competition weight parameter \(w_{c}\) (Fig. 3) that is a priori chosen.

$$ E_{overlap} \left( {i,j} \right) = \left\{ {\begin{array}{*{20}l} {w_{c} A_{c} \left( {{\text{i}},{\text{j}}} \right),} \hfill & {D1 \cap D2 \ne \emptyset } \hfill \\ {0,} \hfill & {D1 \cap D2 = \emptyset } \hfill \\ \end{array} } \right.{ } $$
(11)

With D1, D2 being the pixels belonging to contour i and j, respectively and \(A_{c}\) is the area of overlap between two cells. Then, the regularization energy term \(E_{r}^{{}}\) (Eq. 6) can be rewritten to include the competition terms for a contour i with a neighboring contour j as:

$$ \begin{array}{*{20}c} {E_{r}^{i} = w_{\kappa } E_{\kappa } { } + { }w_{A} E_{A} + { }w_{AS} E_{AS} } \\ \end{array} + E_{dist} \left( {i,j} \right) + E_{overlap} \left( {i,j} \right) $$
(12)

The term is incorporated similarly in the energy term \(E\) and thus has to be minimized (as in Eq. 2) to find the optimal contours.

Landmark-based geometrical transformation and ROI tracking

While we aim at effective cell tracking in every scenario using BEAS cell tracking, there are known challenges that can constrain tracking using active contour methods. These challenges include parameter sensitivity causing the algorithm to be suboptimal for some cells in the field of view, despite being successful for other cells. Therefore, we introduce a robust optional step that uses the tracked locations of \(N\) cell contours using the BEAS approach as landmarks to find the optimal geometrical transformation T that represents the movement in the recorded scene between frames. The optimal parameters \(\theta^{*}\) of T are estimated by minimizing the similarity measure \({\text{d}}\)41,42 which represents the Euclidian distance of the cell contour coordinates between two frames:

$$ \theta^{*} = argmin{ }_{\theta } {\text{d}}\left( {{\text{f}}_{T} ,{\text{f}} + 1} \right) = argmin{ }\mathop \sum \limits_{i = 1}^{N}\| x_{i}^{f + 1} - T\left( {x_{i}^{f} } \right)\|^{2} $$
(13)

With \(x_{i}^{f}\) being the centroid coordinates \(x\) of the contour \(i\) in frame \(f\). This geometrical transformation allows us to move additional ROIs selected manually by the user posthoc throughout the recording frames by performing the geometrical transformation T43 on the positions of the ROIs.

Implementation details

Initialization is done by manually selecting ellipses that roughly overlap with the targeted cell bodies. These ellipses are fed as initial contours to the first frame segmentation step. The result of contour segmentation in a frame is then used for contour initialization in the next frame. Practically, the neighborhood radius ρ determines the range of cell movement between frames that is detectable by the segmentation step. ρ is chosen empirically to detect large movements without extending far off the cell edge and losing its ability in finding local cell edges and relies on multiple parameters including image resolution and relative movement (Suppl. data). During the initialization step, overlap was not allowed to simplify the initial contour interactions and limit entanglement in later segmentation steps.

We choose to represent the B-spline contours in polar coordinates because cell bodies appear as closed ellipses. Therefore, the geometry functions took the form of r = ψ(θ). The geometrical center of the contour shape is calculated and the pole of the contour coordinates translated to this point after each time step (Suppl. Fig. 1). This step is essential as contours cannot be represented as a polar curve if the pole (coordinates’ origin) is outside of the cell contour.

The angular discretization factor denoting contour boundary nodes was set empirically to 32 nodes with regular angular interval dθ. When applied to the experimental recordings, this setting was found to provide a good balance between shape flexibility and representation at a reasonably low computational cost. We measured its effect and that of other parameters in a dedicated parameter sensitivity test. New contour nodes were resampled after the translation step to preserve the accuracy levels of the discretization and maintain the regular interval dθ. This was done by using linear interpolation of the contour nodes’ coordinates (r`, θ`) for polar angles θ` with a regular dθ interval.

A modified gradient descent with feedback step-adjustment was used to perform the energy criterion minimization as explained in previous BEAS implementations16,35. After implementation in MATLAB (ver. R2020b) Runtime was linearly dependent on the number of cells and the image size. The geometrical transformations T used in landmark-based ROI tracking is implemented in the form of a polynomial affine transformation44.

Results

Segmentation strategy evaluation

To objectively evaluate the presented segmentation strategies, we created an artificial dataset that simulates the Ca2+ imaging scenes, featuring movement at rates similar to what is measured in ENS recordings, several intensity-change patterns that represent Ca2+ activity, overlapping neighboring cells with similar baseline intensities, and multiple blurred frames to mimic out-of-focus imaging frames (Fig. 4).

Figure 4
figure 4

Tracking of overlapping cells with the same base intensity level during rest and different intensity levels during activity using (A) one-layer contours without a competition parameter (left) and with a competition penalty added (right) and (B) double contours without a competition parameter (left) and with a competition penalty added (right) (C) Extracted signals from a cell using one-layer contours (top) and double contours (bottom).

We analyzed the signals in this dataset using four different approaches and compared how the extracted signals matched the ground truth signals. Using one-layer segmentation which targets the cytoplasmic border only, without the competition term, expectedly yields poor results, with contours overlapping significantly as the contour nodes cannot find clear edges or intensity gradients (Fig. 4A, left). As a result, the extracted signals are contaminated with information from neighboring cells. On the other hand, using the competition term in addition to the fixed global curvature term anchors the contours and restricts their shapes to prevent them from taking over neighboring cells (Fig. 4A, right), which improves the extracted signal quality drastically. In contrast, the double contour segmentation maintains the general shape even without a competition penalty due to the coupling between the two segmentation layers although a slight overlap can be observed. The small overlaps, in this case, are alleviated when the competition term is added (Fig. 4B).

Signals extracted from the artificial dataset confirm that one-layer contour tracking, without competition, is not reliable in extracting the original signal. This is shown in Fig. 4C top, where the activity from the neighboring cell appears in the activity trace of the measured cell (Fig. 4C, top row, red trace). Double contour segmentation and one-layer contours with competition terms, have no such issues and allow extraction of an accurate signal shape. This is especially the case for double contour segmentation, where the raw fluorescence level is closer to the original because now the dark nucleus pixels can be excluded from the calculation of the cytoplasm intensity (Fig. 4C, bottom).

Parameter sensitivity analysis in an artificial dataset

The impact of each of the selected parameters on segmentation and tracking results using active contours in both one-layer and the double contour methods are estimated by calculating the mean Root Mean-Square Error (RMSE), which is a measure of the difference between observed values and a reference, and in this case, between the extracted signals and reference or ground truth signals. (Fig. 5).

Figure 5
figure 5

Parameter sensitivity analysis: comparison between one-layer vs. double contours where the Y-axis is the normalized RMSE of the extracted signals compared to the raw signals: (top left) effect of radius length values on segmentation sensitivity, double contour segmentation has less segmentation error for all values in the relevant range > 3. (top right) effect of the number of contour nodes: higher RMSE for one-layer segmentation for all values, note the segmentation failure of double contour method at low (e.g. sixteen) contour nodes number, as indicated with x. Curve regulation term (bottom left). Competition term (bottom right): lack of competition term causes high normalized-RMSE for one-layer segmentation.

The first parameter ρ, the neighborhood radius (Fig. 5, top left), expectedly has, for smaller values, a big influence on the tracking results. Afterwards, the tracking is stable for several values until the radius is too large and tends to encounter multiple edges simultaneously. The second parameter, the matrix size, which determines the number of discretized contour nodes negatively affects the tracking at smaller matrix sizes (fewer number of nodes) for both one- and double contour tracking, with failure to track cells in case of double contour segmentation with the lowest (only sixteen) number of nodes (Fig. 5, top right). This indicates that due to its extra complexity, double contour segmentation is more sensitive to the number of nodes. While the curvature term does not affect the accuracy of segmentation (Fig. 5, bottom left), the addition of a competition term does improve segmentation, especially for the one-layer segmentation option. The effect of a competition term with double contour segmentation is negligible in this dataset (Fig. 5, bottom right).

Experimental results

When applied to actual recordings, we find that the proposed approach successfully tracks cells throughout significant tissue movements (Fig. 6, Top panel), allowing us to reliably resolve Ca2+ peaks from the extracted signals (Fig. 6, bottom panel).

Figure 6
figure 6

Contours of multiple cells and cell movement (top). Pixel intensity signal from the one tracked cell in the top panel and the contour appearance at multiple time points before, during and after a peak in Ca2+ activity.

To compare with traditional analysis methods, we analyzed recordings with both the new contour tracking method as well as with manual routines, involving motion correction and rectangular ROI selection by a blinded expert. For that purpose, we used datasets of 3 recordings to compare the degree of similarity of the signals extracted by the traditional method against the one-layer contour and double contour methods, respectively (Fig. 7A,B). We found that Ca2+ profiles are very comparable in shape between extraction from tracked cells versus manually drawn ROIs, with a normalized root-mean-square error (RMSE) of 0.093 and 0.114 for one-layer or double contours respectively (Fig. 7B).

Figure 7
figure 7

(A) Contours of tracked cells and manual rectangular ROIs which are moved based on the contours tracked. (B) RMSE of signals extracted using 1 layer (red) and double contour (blue) versus manually selected ROIs by an expert. (C) Comparison of the extracted signals (red/blue mean, light red/blue standard deviation) against a ground truth artificial peak (dotted green) using 1-layer contour tracking (left) and double contours (right) based on 22 cells. (D) RMSE of signals extracted from 22 cells injected with the artificial peak using manual ROIs (left), 1 layer (center) and double contour (right) versus the ground truth.

True validation of our analytical approach is not straightforward as it requires assessing the quality of signal extraction against a ground truth signal. Since the latter should be fully known, yet embedded in a context that holds all the biological, optical, and experimental complexity, we generated artificial Ca2+ peaks in real Ca2+ recordings in the cytoplasm of multiple moving cells (Suppl. movie 1). Then we used the contour cell tracking method to re-extract the Ca2+ signals and compared the extracted signals to the original planted signal. We found that the Ca2+ peak shape was preserved in most cells (Fig. 7C), and the median RMSE in the one-layer and double contour approach to be 0.1216 and 0.1738 (based on 22 tracked cells) to be comparable to that of the manually selected ROIs with an RMSE of 0.1212 (Fig. 7D). The higher RMSE values of DC tracking are simply due to a few complete tracking failures, see Discussion.

Finally, we used the newly developed tracking approach on actual recordings of ENS tissue (Suppl. movies 22, 3) including movement in x and y and out-of-focus frames. We found that with optimized parameters one-layer segmentation, proves reliable to track many cells in the field of view. Notably, the segmentation procedure performs well despite the presence of blurry out-of-focus frames (Fig. 7), which is an important advantage compared to edge-based segmentation techniques45. In double contour segmentation, we observed less overlap of contours without a competition penalty resulting in good reliability in cells with non-visible edges. However, this method had more difficulties in scenes with faster movement and was expectedly not robust in cells without contrast between the nucleus and cytoplasm. While this new approach performs well, it is unavoidable that cell tracking fails to resolve some cells with challenging appearance or location in the image. The developed landmark ROI-tracking exploiting the known trajectory of successfully-tracked cells proved to be a useful and robust tool to overcome this challenge with minimal computational power needed (Suppl. movie 4). In addition, it gives the researcher the additional ability to extract signals from smaller structures, like cell processes or glial cells (Fig. 7A).

Discussion

Given the complexity of Ca2+ imaging in the contractile ENS tissues, where a scene not only contains moving cells but these cells also display irregular fluorescence intensity changes11, traditional methods based on image registration and ROI selection are cumbersome and prone to failure during signal extraction and quantitative analysis3,10,46,47. Additionally, low-level cell tracking techniques cannot function reliably in this scenario due to multiple reasons, including low signal-to-noise ratio (often the case in live imaging), cellular overlap and variable cellular edges, which depend both on the imaging system and the labeling approach, as well as on the activity of the cell48. In this paper, we developed a cell tracking algorithm targeted specifically to track neurons in such a challenging contractile scenario, with the additional complexity that cells in Ca2+ imaging have blurry borders and constantly change fluorescence intensity. Our method successfully tracks blinking cells in moving ENS tissue, without the need for non-rigid image registration. The extracted temporal signals are comparable in quality to manual, expert-selected ROIs. Furthermore, the tracked cell coordinates allow additional rectangular ROI tracking and add robustness and flexibility to the workflow to process the most challenging recordings.

Comparison of segmentation strategies

In an artificial dataset that was created to simulate cell shape and behavior, specifically having moving cells without clear borders, we found the competition term to be important in one-layer cell tracking as the contours overlap and the contour nodes do not find edges to adhere to in their absence. The addition of a competition term and a significant curvature term prevents them from taking over neighboring cells resulting in good signal extraction.

The performance of cell segmentation in this simulated dataset is consistently improved by using the novel double contour method. The double contour uses the inner nucleus contours as a natural anchor that restricts the outer contour from taking over neighboring cells. It can conserve the shape with low, or even without, competition and curvature terms. However, the advantage of the coupled double contour approach is limited in recordings with large cell displacement between frames as it depends on tracking the smaller nucleus from its position in the previous frame. In this case, higher image acquisition rates are required, which adds complexity to the imaging setup, generates bigger datasets, and causes longer processing times. Nevertheless, we consider the double contour approach to be powerful in its application to GCaMP based recordings, as the reporter is genetically prevented from entering the nucleus, leaving the nucleus dark and thus enabling accurate tracking of cells and signal extraction selectively from the cytoplasm.

Parameter sensitivity analysis

Active contours are heavily reliant on multiple parameters and can be sensitive to parameter values limiting their robustness. Segmentation and tracking results are reliant on the values of multiple parameters controlled by the user. This means that a minimal understanding of how they might affect the final outcome is required49, which is a drawback of all parametric segmentation models. Therefore, we quantified the effects of the global penalty terms on the algorithm’s performance in both the one-layer and double contour strategies, by extracting and comparing the signals from simulated data. We observed general similarity in sensitivity to the studied parameters, except for the inability to track cells when using only a few contour nodes in the double contour, which is at odds with the increased complexity of this strategy. The introduction of the cell competition term improved cell tracking when using one-layer contours, reduced the error rate to similar values as obtained by double contours in this dataset. Although the curvature term did not increase the accuracy of the extracted signal in the simulated dataset, it plays an important stabilizing role to the cell contours in real recordings, especially in blurred images or in frames where segmentation is struggling to delineate cells returning to baseline fluorescence. We found that tracking is generally insensitive to a wide range of parameter values in the simulated dataset despite our efforts to introduce the most challenging conditions, which all together indicate that the performance of the algorithm is robust.

In general, the global penalty terms are valuable to limit segmentation failure, which is a known drawback of active contour segmentation33. However, they do not show significant effects on tracking results of cells that are already well within the means of the method, as shown in Fig. 5.

Experimental results

As the aim of the new approach was to extract accurate Ca2+ signals from experimental data, we compared contour tracking to the traditional extraction method and found a high similarity of the extracted signals between the two methods. We used an artificially embedded Ca2+ peak to measure the similarity to the ground truth and found that these planted peaks were indeed detected in most cells, demonstrating the applicability of the contour tracking workflow. The artificially embedded Ca2+ peaks were then used to compare the quality of the signal extraction using the two contour types against the traditional extraction method. Results from the one-layer contours were highly similar to those of the traditional method in their error between the extracted signal and the ground truth values of the artificial peak (Fig. 7). We observed slightly lower average similarity between the ground truth signal and double contour method, which was mainly due to instances where the method failed to track those neurons without contrast between the nucleus and cytoplasm, which we, in order to be as close to reality as possible, also included in the dataset. This is easily mitigated by using the additional ROI tracking option, which we introduced to extract signals from cells for which contour tracking is inaccurate (Fig. 2A).

Practically, we find one-layer tracking to be robust in recordings with blurry out-of-focus frames and its stability largely depends on the neighborhood radius ρ in relation to movement intensity in-between frames. Furthermore, the introduction of a cell competition term improves cell tracking and reduces the error in experimental recordings. Double contour tracking on the other hand is useful when the recording is not blurry and the movement in-between frames is generally less than the nucleus diameter. The latter limits the applicability in recordings with substantial displacement due to rapid muscle contractions, especially when fast image acquisition is not feasible. Its main advantage, which results from the inner nucleus contour acting as an anchor to the outer cellular contour, is the ability to track overlapping cells without clearly visible borders, a common sight for ENS neurons in the submucosal layer6. Therefore, the two methods are complementary and can be used by subjectively assessing the recording at hand. The landmark-based ROI tracking possibility for manually-added ROIs provides a useful addition that allows tracking challenging cells, which the active contours method fails to correctly segment. It is a useful tool as it does not require re-running the tracking workflow and is applied post-hoc, providing a robust option fully controlled by the user. Compared to activity-based signal extraction methods used in Ca2+ imaging, which require successful image registration and completely static scenes to then provide Ca2+ signals from active cellular regions50,51, this method allows for efficient analysis of Ca2+ imaging datasets with a non-static scenery regardless of the effectiveness of image registration.

The method developed by Hennig et al.10, specifically for ENS tissue requires image thresholding of the bright cytoplasm-dark nuclei interface to segment nuclei and extract signals, which is suitable for non-blurry recordings of the bright GCaMP3 Ca2+ indicator10. In contrast, we are able to successfully track cells in partially-blurry recordings and using the more dynamic, but dimmer at rest, Ca2+ indicator GCaMP6f. This helps us in analyzing faster neuronal activity and detecting the Ca2+ transients elicited by individual action potentials52.

Conclusion

To satisfy the need for a robust analysis tool for Ca2+ imaging in moving and contractile tissues, we introduced an efficient hybrid approach to track cell bodies relying on local region-based terms in evolving the contour, avoiding the disadvantages of region-based segmentation (Fig. 2). We further developed a novel ‘double contour’ or coupled-layers tracking algorithm that takes advantage of the fact that cells in genetically encoded Ca2+ imaging techniques appear with dark nuclei. We quantified the method’s performance in an artificial dataset that simulates experimental challenges under different parameter values and compared the two tracking algorithms. We then tested the algorithm’s robustness in tracking neurons in various ENS tissue Ca2+ recordings and demonstrate, using embedded artificial Ca2+ spikes, that the method reliably captures these spikes and represents them in the extracted signals. We expanded the analysis possibilities by implementing land-mark based ROI tracking, which increases the robustness of the workflow for challenging datasets. Finally, we packaged the workflow as a MATLAB GUI to enable efficient analysis of Ca2+ imaging datasets with a non-static scenery. This novel cell tracking method uses multiple features of ENS neurons activity and appearance to effectively segment, track and extract the Ca2+ signals from complex and biologically relevant recordings. It has the explicit advantage that it can deal with dramatically changing intensities, even when very dim and hardly above noise levels. Moreover, the technique behaves robust even if out-of-focus frames are present in the recordings. Even though the ENS was used as a model system, the technique can still be used on other cellular recordings by tweaking the contour parameters to match the specific application.