1. Registration#
Note
The terms motion-correction and registration are often used interchangeably. Similarly, non-rigid and piecewise-rigid are often used interchangeably. Here, piecewise-rigid registration is the method used to correct for non-rigid motion.
1.1. Overview#
We use suite2p:registration to ensure spatial alignment across all frames in a movie. This means a neuron that appears in one location in frame 0 remains in the same spot in frame N.
Registration uses either a single-channel movie (default: channel 1), or an alternate channel if ops['align_by_chan'] = 2
.
The result of registration is a binary file (data.bin
) aligned to a reference frame. Suite2p creates this reference frame by selecting the top correlated subset of frames and refining their alignment iteratively. You can customize this via ops['nimg_init']
.
from suite2p.registration import register
refImg = register.pick_initial_reference(ops)
Use ops['refImg']
to inspect the reference if needed.
1.2. Rigid and Non-Rigid Registration#
Suite2p first runs rigid registration (frame-wide shifts using phase correlation), followed by optional non-rigid registration (local shifts in blocks).
Set ops['nonrigid'] = True
to enable block-based correction.
1.2.1. Key Parameters#
Parameter |
Description |
---|---|
|
Channel to align by (1 or 2). |
|
Whether to apply non-rigid registration. |
|
Size of blocks in [Y, X] for nonrigid. Default |
|
Maximum fraction of FOV allowed to shift (rigid). |
|
Max shift in pixels for non-rigid registration. |
|
Gaussian smoothing sigma. Improves template clarity. |
|
Number of frames per registration batch. |
Recommended tuning
Increase
nimg_init
if your template looks noisy or blurryIf there is remaining motion after rigid, try
nonrigid = True
If registration looks unstable, try decreasing
maxregshift
ormaxregshiftNR
1.3. Output Files#
data.bin
: motion-corrected movie (channel 1)data_chan2.bin
: registered channel 2 (ifnchannels = 2
)ops['xoff']
,ops['yoff']
: rigid shifts for each frameops['corrXY']
: phase-correlation scores frame vs reference
1.4. Metrics#
Suite2p computes PC-based registration metrics via registration:
from suite2p.registration import metrics
ops = metrics.get_pc_metrics(ops, use_red=False)
Metric |
Description |
---|---|
|
Spatial principal components used to compute metrics. |
|
Time courses of principal components used for alignment QC. |
|
Shift distance between split PCs. Lower values = better registration. |
You can visualize these with Suite2p’s GUI or custom plotting tools. Even with good metrics, always visually inspect registered frames.
Important
Visual inspection trumps all. Even if regDX
is low, double check the video. And if it looks good but metrics are high, trust your eyes.
1.5. CLI for Registration Metrics#
You can also use the command-line:
reg_metrics path/to/data --nplanes 1 --smooth_sigma 1.2
To see available CLI options:
reg_metrics --help
Example output:
Avg_Rigid: 0.000000 Avg_Average NR: 0.028889 Avg_Max NR: 0.120000
Max_Rigid: 0.000000 Max_Average NR: 0.044444 Max_Max NR: 0.200000
These values are from ops['regDX']
, and should be close to zero in well-registered data.