3. Segmentation#

Function for this step: segmentPlane()

3.1. Segmentation Overview#

Warning

segmentPlane() will take significantly longer than the previous steps.

Much of work is about separating “good activity”, the flourescence changes that we can attribute to a single cell, vs “noise, which is everything else (including signal from other neurons).

To do this, we take advantage of the fact that a slow calcium signal is typically similar between adjacent frames.

The speed of transients, or the time it takes for the neuron to fully glow (rise time) and unglow (decay time), is a very important metric used to calculate several of the parameters for CNMF.

In particular, speed of transients relative to the frame rate can be thought of in terms of “how many frames does it take my calcium indicator to undergo a complete transients cycle”.

The flourescence of the proteins in our neurons is correlated with how active the neuron is. Turning this flourescence into “spikes” relies on several mathmatical operations to:

  • isolate neuronal activity from background activity (segmentation).

  • infer the times of action potentials from the fluorescence traces (deconvolution).

3.2. Inputs#

Inputs are consistent with Registration, substituting::

NoRMCorreSetParams -> CNMFSetParams

All of the parameters and options fed into the codeCNMF pipeline are contained within a single MATLAB struct.

Note

There is an example file describing CNMF parameters at the root of this project. demo_CNMF_params.

3.3. Tuning CNMF#

To get an idea of the default parameters (what happens if you use CNMFSetParams() with no arguments), you can run the following code to see the defaults:

>> opts = CNMFSetParams()

There are several different thresholds that correlation coefficients must cross to be considered a “valid” neuron or a “valid” transient signal.

Below are the CNMF parameters that control these thresholds and allow tuning the algorithm to your dataset.

3.3.1. merge_thresh#

A correlation coefficient determining the amount of correlation between pixels in time needed to consider two neurons the same neuron.

  • The lower your resolution, the more “difficult” it is for CNMF to distinguish between two tight neurons, thus use a lower merge threshold.

  • This parameter heavily effects the number of neurons processed. It’s always better to have to many neurons vs too few, as you can never get a lost neuron back, but you can invalidate neurons in post-processing.

3.3.2. min_SNR#

The minimum signal-noise ratio needed for the algorithm to accept a neurons initialization (accept it as valid).

This value is used for an event exceptionality test, which tests the probabilty if some “exceptional events” (like a spike).

Hint

If this value is low, even a very slight deviation in signal will be considered exceptional and many background-neurons will be accepted.

  • The likeihood of observing the actual trace value over N samples given an estimated noise distribution.

  • The function first estimates the noise distribution by considering the dispersion around the mode.

This probability is used to order the components according to “most likely to be exceptional”.

3.3.3. Tau#

Half-size of your neurons.

  • Tau is the half-size of a neuron. If a neuron is \(10μm\), Tau will be a \(5μm\).

  • In general, round up.

  • This changes depending on the area of the brain you’re in and should be adjusted to match the ~cell size of the brain region.

Note

If this parameter is not included, they will be calculated for you based on the pixel_resolution, frame rate and image size in the metadata.

  • For example, Tau is a widely talked about parameter being the half-size of your neuron.

This is calculated by default as 7.5/pixel_resolution.

This makes sense if we assume an ~neuron size of \(14μm\).

3.3.4. P#

This is the autoregressive order of the system.

  • It is a measure of how the signal changes with respect to time.

  • This value will always be 1 or 2, depending on the frame rate of the video and the dynamics of the calcium indicator.

Tip

In general, If your indicator takes >1 frame to rise/decay, P=2 (slow) otherwise, P=1 (fast)

3.4. Segmentation Outputs#

The .h5 output for segmentation contains several groups. You will not find any movies, those are stored in the registration outputs.

3.4.1. H5 Groups#

The output of the analysis includes several key variables that describe the segmented neuronal components and their corresponding activities.

Below is a description of each output variable, along with an example of how to use them and what they represent.

  1. T_all: Neuronal time-series

    • The fluorescence time-series data for each detected neuronal component. Each row corresponds to a different neuron, and each column corresponds to a different time point.

    • This data can be used to analyze the temporal dynamics of neuronal activity, such as identifying patterns of activation over time.

  1. C_all: Deconvolved neuronal activity

  • The deconvolved activity traces, which represent the estimated underlying neuronal firing rates. This data is derived from T_all through a deconvolution process that attempts to remove the effects of calcium dynamics.

  • This data can be used to study the inferred spiking activity of neurons, which is often more directly related to neuronal communication than raw fluorescence data.

  1. N_all: Neuronal spatial coordinates mapped to X/Y coordinates

  • A matrix where each row represents a neuron, and the columns contain properties such as the neuron’s integrated fluorescence (acm), x-coordinate (acx), y-coordinate (acy), and z-coordinate (plane_index).

  • This data can be used to analyze the spatial distribution of neurons within the imaging field and correlate spatial properties with functional data.

  1. Ac_keep: Neuronal footprints

  • The spatial footprints of the detected neurons. Each neuron is represented by a 2D matrix showing its spatial extent and intensity within the imaging field.

  • This data can be used to visualize the spatial arrangement and morphology of neuronal components.

  1. Cn: Correlation image

  • A 2D image showing the correlation of each pixel’s time-series with its neighboring pixels, highlighting areas of correlated activity.

  • This image can be used to identify regions of interest and assess the overall quality of the motion correction and segmentation process.