LabCanvas
Image analysisPublished Last updated

Drift correction in ImageJ and Fiji: StackReg, Correct 3D Drift or SIFT?

Correct drift in a Fiji time-lapse with StackReg (BIG-EPFL update site), Correct 3D Drift or Linear Stack Alignment with SIFT: which to use and how.

A drifting time-lapse: frame 1 in green over frame 30 in magenta, offset by about 11 pixels, and the same two frames in white where they agree after frame 30 is shifted back
A drifting time-lapse: frame 1 in green over frame 30 in magenta, offset by about 11 pixels, and the same two frames in white where they agree after frame 30 is shifted back.
Contents

To correct drift in a time-lapse in Fiji, use Plugins › Registration › Correct 3D drift for stage drift (the whole field sliding): it comes with Fiji, measures the shift between frames by phase correlation on one channel, works on 2D and 3D time-lapses, and makes a new, aligned hyperstack. When the sample also rotates, use StackReg (install the BIG-EPFL update site first; Translation, Rigid Body, Scaled Rotation or Affine), or Plugins › Registration › Linear Stack Alignment with SIFT, which matches features and copes with large shifts and changes in brightness.

Your time-lapseUseWhy
Stage drift only, 2D or 3D, one or more channelsCorrect 3D driftIncluded in Fiji; translation in x, y (and z); one channel drives all of them
Drift plus rotation, one channel, 2DStackReg, Rigid BodyIntensity-based, sub-pixel; needs the BIG-EPFL update site
Large jumps, rotation, or frames whose brightness changes; texture with distinct featuresLinear Stack Alignment with SIFTFeature matching does not need frames to look alike overall
Two channels offset from each other (chromatic shift)None of these aloneMeasure the shift between channels once, on beads, and move one channel

Below: how to see drift and prepare the stack, each tool step by step with its options, the pitfalls that ruin measurements afterwards, and a methods sentence.

Do I have drift? Check before you correct

Drift is the whole field of view moving between frames: the stage creeps, the dish settles, the focus wanders with temperature. It turns stationary structures into tracks, smears time projections and biases every measurement that assumes a fixed position (kymographs, ROIs over time, particle tracking).

Two quick checks:

  • Max projection over time: Image › Stacks › Z Project…, Max Intensity. Sharp structures mean little drift; doubled or smeared ones mean drift.
  • First against last frame: duplicate frame 1 and the last frame (Image › Duplicate… with the range), then Image › Color › Merge Channels… with one in green and one in magenta. Grey or white where they agree, colour fringes where they moved.
Frame 1 in green and frame 30 in magenta of a drifting time-lapse, then the same two frames after frame 30 is shifted back
A synthetic drifting time-lapse the LabCanvas Align sample: 30 frames, 0.2 µm pixels. Left: frame 1 green and frame 30 magenta are 10.7 px apart sideways and 4.9 px vertically, so every spot is doubled. Right: frame 30 moved back by that known drift; the two agree white except for spots that blink.

Before any of the tools:

  1. Check the axes: Image › Properties… must say the time points are Frames, not Slices. Movies often open as z-slices.
  2. Work on a copy (Image › Duplicate…, Duplicate stack), and keep the original for intensity measurements.
  3. Know what should stay still. Registration lines up the image content. If the cells themselves move or change shape a lot, the tools can follow them instead of the stage; register on a channel or region with structures that only drift (beads, a membrane stain, the substrate).

Correct 3D Drift (included in Fiji)

Correct 3D Drift is a script that ships with Fiji. It measures the translation between consecutive time points by phase correlation and shifts every time point back, in x and y, and in z for 3D time-lapses (Parslow, Cardona and Bryson-Richardson 2014). It handles hyperstacks: the drift is measured on one channel and applied to all.

  1. Open the time-lapse and check Image › Properties… (frames, not slices).
  2. Optional: draw a rectangle around a region that should stay still. The script then measures drift only there, and moves the rectangle along with the drift.
  3. Plugins › Registration › Correct 3D drift.
  4. Set the options and click OK. A new, registered hyperstack opens; the original is left unchanged.

The dialog, option by option:

OptionWhat it does
Channel for registrationThe channel the drift is measured on; all channels are moved
Correct only x & y (for 3D data)Ignore z drift in a 3D time-lapse
Multi_time_scale computation for enhanced detection of slow drifts?Also compares frames 3, 9, 27… apart, which catches drift slower than a pixel per frame
Sub_pixel drift correction (possibly needed for slow drifts)?Shifts by fractions of a pixel (interpolated); off, it shifts by whole pixels
Edge_enhance images for possibly improved drift detection?Measures on edge-enhanced images
Only consider pixels with values larger thanSubtracts this value before measuring, so dim background weighs less
Lowest / Highest z plane to take into accountThe z range used for measuring
Max_shift_x, Max_shift_y, Max_shift_z [pixels]The largest shift accepted between compared frames (10 by default): raise it if the drift jumps further
Use virtualstack for saving the results to disk to save RAM?Writes the result to a folder instead of memory, for big data
Only compute drift vectors?Measures the drift without making the aligned stack

If it answers "Cannot register because there is only one time frame", ImageJ has read your frames as slices: fix it in Image › Properties… as in step 1.

StackReg (BIG-EPFL update site)

StackReg, from the Biomedical Imaging Group at EPFL, aligns each slice of a stack to its neighbour by minimising the intensity difference with a coarse-to-fine pyramid, to sub-pixel precision (Thévenaz, Ruttimann and Unser 1998). It is not part of Fiji's default plugins.

Install it: Help › Update…, click Manage update sites, tick BIG-EPFL, click Close, then Apply changes and restart Fiji. That adds StackReg and TurboReg, which StackReg needs. On a server without a screen, the command-line Updater does the same: ./fiji --update add-update-site BIG-EPFL https://sites.imagej.net/BIG-EPFL/, then ./fiji --update update.

Run it:

  1. Duplicate the stack: StackReg changes the stack in place.
  2. Go to the frame you want everything aligned to (frame 1, or a sharp frame in the middle). StackReg uses the slice shown when it starts as the anchor: that slice is not moved.
  3. Plugins › Registration › StackReg.
  4. Choose the Transformation and click OK. The other slices are aligned one after another outwards from the anchor, each to its already aligned neighbour.
TransformationAllowsUse it for
TranslationShifts in x and yStage drift
Rigid Body (the default)Shifts and rotationA sample or dish that also turns
Scaled RotationShifts, rotation and a change of sizeZoom or magnification changes
AffineShifts, rotation, scaling and shearSections or samples that deform

Choose the simplest transformation that describes the motion. Because every slice is aligned to the previous one, one bad registration (a blurred frame, a frame with a bubble) carries into all the frames after it.

StackReg aligns every plane of the stack as one sequence. On a multichannel or z-stack hyperstack, split the channels first (Image › Color › Split Channels) and register one, or use Correct 3D drift, which moves all channels together. TurboReg, installed with it, aligns one image onto another and is what StackReg calls for each pair.

Linear Stack Alignment with SIFT (included in Fiji)

This plugin finds distinctive points (SIFT features, after Lowe 2004) in each slice, matches them between consecutive slices, and estimates the transformation from the matches that agree. Because it matches features rather than whole images, it handles large jumps and frames whose overall brightness changes, as long as the image has texture with distinct features.

  1. Plugins › Registration › Linear Stack Alignment with SIFT.
  2. The main settings: expected_transformation (Translation, Rigid by default, Similarity or Affine), maximal_alignment_error (25 px by default: how far a matched point may lie from where the transformation puts it), inlier_ratio (0.05: the share of matches that must agree) and interpolate (ticked).
  3. OK. A new window, "Aligned … of …", fills slice by slice, starting from slice 1 unchanged; the original stack is left as it is.

For a multichannel stack, Linear Stack Alignment with SIFT MultiChannel in the same menu asks for a Registration_channel and applies the alignment found on it to every channel. On smooth, feature-poor images (a uniform cell, large flat regions), SIFT finds too few matches; use Correct 3D drift or StackReg there.

Which one should I use?

Correct 3D driftStackRegSIFT
Comes with FijiYesNo: BIG-EPFL update siteYes
MotionTranslation (x, y, z)Translation, rigid, scaled rotation, affineTranslation, rigid, similarity, affine
3D time-lapsesYesNo (2D stacks)No (2D stacks)
Several channelsYes, one drives allNo: one channel at a timeYes, MultiChannel version
MethodPhase correlationIntensity, pyramid, sub-pixelFeature matching
ResultNew hyperstackSame stack, changedNew stack

Pitfalls

  • Correcting the biology away. Registration follows whatever dominates the image. A spreading or migrating cell can be "aligned" until it stops moving. Register on stable structures (a region, a channel, beads) and check a Max projection of the result.
  • Interpolation and intensities. Sub-pixel shifts, rotations and scaling interpolate pixel values. For intensity measurements, use whole-pixel translation where possible, or measure in the original with ROIs moved by the drift.
  • Black borders. Pixels shifted in from outside the field are zeros. Crop to the region present in every frame before measuring means, thresholds or backgrounds.
  • Repeating patterns. Grids and perfectly regular structures can register one period off; Parslow and colleagues note that such samples are not suitable for this kind of registration.
  • Focus drift is not drift correction. A 2D movie that goes out of focus cannot be fixed by moving pixels; for 3D time-lapses, Correct 3D drift corrects z position, not blur.
  • Order with other corrections. Correct drift before kymographs, ROIs over time and tracking. Bleach correction measures in fixed regions, so align first if the field moves (see bleach correction).

Reporting it

A methods sentence to copy:

Sample drift was corrected in [Fiji (ImageJ 1.54f)] with [Correct 3D Drift (Parslow et al., 2014), registering on the [membrane] channel, [sub-pixel] / StackReg (Thévenaz et al., 1998), [Translation], anchored on frame [1] / Linear Stack Alignment with SIFT (Lowe, 2004), [Rigid]].

Give the tool, the transformation, the channel or region used and whether shifts were sub-pixel, and show a Max projection over time before and after in the supplement.

An easier way: drift correction in LabCanvas

The Process tab of LabCanvas Image Analysis has an Align section that corrects drift in the browser, with nothing to install and no update site.

  1. Open the time-lapse, or load the drifting sample shown above from the Align section.
  2. Choose Drift, then what to line each frame up with: the First frame, the Previous frame or the Mean. Optionally draw a rectangle around stable structures: the drift is measured there.
  3. Pick the channel to Measure on (all channels are moved) and the Precision (whole pixels to 1/100 pixel), and untick Sub-pixel shifts (bilinear) to keep pixel values unchanged.
  4. Click Correct drift. The aligned stack opens as a new image, and the drift of every frame goes to a table and a chart.
Drift correction in LabCanvas Image Analysis
Drift correction: Drift of every frame measured against the first and corrected: largest drift 2.345 µm, at frame 30.

It measures the shift by phase correlation, like Correct 3D drift, and corrects translation only: no rotation or affine transformations, and no z drift between time points. Channels in the same section measures and corrects the shift between two channels. Measuring is free with a LabCanvas account (downloading files is part of LabCanvas Pro), and the processing is checked in more than 8,900 automated tests. For rotation, affine distortions or 3D time-lapses, use StackReg, SIFT or Correct 3D drift in Fiji. ImageJ and Fiji are independent open-source projects; LabCanvas is not affiliated with them.

References

  • Parslow A, Cardona A, Bryson-Richardson RJ (2014). Sample drift correction following 4D confocal time-lapse imaging. Journal of Visualized Experiments (86), e51086. doi:10.3791/51086
  • Thévenaz P, Ruttimann UE, Unser M (1998). A pyramid approach to subpixel registration based on intensity. IEEE Transactions on Image Processing 7(1), 27–41. bigwww.epfl.ch/publications/thevenaz9801.html
  • Lowe DG (2004). Distinctive image features from scale-invariant keypoints. International Journal of Computer Vision 60(2), 91–110. doi:10.1023/B:VISI.0000029664.99615.94
  • Schindelin J, Arganda-Carreras I, Frise E, et al. (2012). Fiji: an open-source platform for biological-image analysis. Nature Methods 9, 676–682. doi:10.1038/nmeth.2019

Frequently asked questions

How do I correct drift in a time-lapse in Fiji?

For stage drift (the whole field moving), use Plugins › Registration › Correct 3D drift, which comes with Fiji: choose the channel to register on and click OK, and it makes a new, aligned hyperstack. It corrects translation only, in 2D or 3D. For rotation as well, install StackReg from the BIG-EPFL update site, or use Plugins › Registration › Linear Stack Alignment with SIFT.

How do I install StackReg in Fiji?

Help › Update…, click Manage update sites, tick BIG-EPFL, click Close, then Apply changes and restart Fiji. StackReg and TurboReg (which StackReg needs) then appear under Plugins › Registration.

Which StackReg transformation should I use?

Translation for stage drift, Rigid Body (the default) when the sample also rotates, Scaled Rotation when it also changes size, and Affine when it shears. Pick the simplest one that fits: more freedom lets StackReg distort the image to match noise or changes in the sample.

Why does Correct 3D Drift say there is only one time frame?

It registers time points, and ImageJ has read your movie as z-slices. Open Image › Properties and swap the numbers: Slices (z) 1 and Frames (t) the number of time points (or use Image › Hyperstacks › Re-order Hyperstack). Then run it again.

Does StackReg work on multichannel hyperstacks?

StackReg treats every plane of the stack as one sequence, so on a multichannel or z-stack hyperstack it aligns channels and slices to each other as if they were time points. Use Correct 3D drift (it measures on one channel and moves all of them), Linear Stack Alignment with SIFT MultiChannel, or split the channels first.

Does drift correction change my intensities?

Sub-pixel shifts and rotations interpolate between pixels, which smooths the image slightly and changes single-pixel values. For intensity measurements, prefer whole-pixel translation when the drift allows, or measure on the original frames with ROIs moved by the measured drift. Pixels that move in from outside the field are filled with zeros: crop them away before measuring.

drift correction ImageJStackRegTurboRegCorrect 3D DriftLinear Stack Alignment with SIFTimage registration Fijialign time-lapseBIG-EPFLstage drift

Try it in LabCanvas

Every app is free to start in your browser. Create an account and begin.

Start Image Analysis free in your browser