Skip to main content
Sandbox Physics

Raster Scan & Drift Recovery

Can aligning repeated frames undo the distortion that drift causes in a scanned image? Distinct features in both directions let you estimate frame-to-frame shifts. On a featureless surface both directions are ambiguous. Parallel stripes leave the shift along them undetermined. Any distortion that develops during a scan remains after the whole frame is shifted.

Acquire a stack of frames, estimate how far each frame has shifted from its counts and compare the plain average with the aligned result. Then try to break the estimate with stripes, a featureless surface, slow scanning and a narrow search window.

Interactive modelRaster Scan & Drift Recovery
Assigned within-frame motion0 nm0\,\mathrm{nm}
Accepted-frame common coverage0 %0\,\mathrm{\%}
Frames used · includes first frame00
Registration status—\text{—}
More measurements and target
Stored frame time0 s0\,\mathrm{s}
Stored acquisition duration0 s0\,\mathrm{s}
Assigned first-to-last motion0 nm0\,\mathrm{nm}
Incident-count relative noise · all frames0 %0\,\mathrm{\%}
Stored 6 nm grating sampling—\text{—}
Estimated first-to-last horizontal shift0 nm0\,\mathrm{nm}
Estimated first-to-last vertical shift0 nm0\,\mathrm{nm}
Lowest accepted image correlation00
Effective committed search radius0 pixel0\,\mathrm{\mathrm{pixel}}
Experiment task—\text{—}

Can recorded frames reveal their own drift?

BackgroundAcquire a stack of fast scans. Estimate each shift from the stored counts and compare the raw and aligned averages. Use the assigned drift as an independent check on the estimate.

Why it mattersAn average can look sharp and still be built on wrong shifts, carry the distortion of the first frame or show aliased detail.

Focus question
When can a shift be worked out from the images alone?
One-sentence intuition
A patch with features in both directions can constrain both shift components if the search finds one unambiguous correlation peak. A uniform surface carries no shift information, and stripes leave the shift along them undetermined. One translation per frame cannot remove the shear that builds up within a frame.

Core mathematical model

Every pixel has its own time

tf,r,c=fTf+ℓ(r)Tl+(c+12)tp,Tl=Ntp+tb,Tf=NTlt_{f,r,c}=fT_f+\ell(r)T_l+(c+\tfrac12)t_p,\quad T_l=Nt_p+t_b,\quad T_f=NT_l

Times are in seconds. A positive stage drift lowers the specimen coordinate that the probe samples. Changing the order of the rows changes the distortion.

Estimate a shift from image correlation

s^f=arg⁡max⁡∣sx∣,∣sy∣≤R  ∑Ω(A−A‾)(Bf(r+s)−B‾f,s)∑Ω(A−A‾)2∑Ω(Bf(r+s)−B‾f,s)2\widehat{\mathbf s}_f=\underset{|s_x|,|s_y|\le R}{\arg\max}\;\frac{\sum_{\Omega}(A-\overline A)(B_f(\mathbf r+\mathbf s)-\overline B_{f,\mathbf s})}{\sqrt{\sum_{\Omega}(A-\overline A)^2\sum_{\Omega}(B_f(\mathbf r+\mathbf s)-\overline B_{f,\mathbf s})^2}}

A is the filtered first frame and B is a filtered stored frame. The window stays fixed inside the image, so nothing wraps around the edges. A coarse search followed by local subpixel refinement can miss a competing peak. Thresholds set for teaching reject estimates that are weak, ambiguous or at the edge of the search range.

Average the accepted frames

J(r)=1∣A∣∑f∈AIf(r+s^f),s^0=0,p<3 nmJ(\mathbf r)=\frac{1}{|\mathcal A|}\sum_{f\in\mathcal A}I_f(\mathbf r+\widehat{\mathbf s}_f),\quad\widehat{\mathbf s}_0=\mathbf0,\quad p<3\,\mathrm{nm}

Only accepted frames are averaged, with their original counts resampled by bilinear interpolation. Pixels outside the area that every accepted frame covers are masked. The first frame is always kept as the coordinate reference; it was never checked as a match itself. To sample the 6 nm grating, the pixel spacing must be strictly below 3 nm.

Common difficulties

A high correlation does not guarantee accuracy

Typical misconceptionIf a match has high correlation and passes the checks, it must be accurate.

Better mental modelThe acceptance thresholds are rules of thumb, not probabilities or calibrated error bars. That is why the task also checks whether every frame was accepted, the sampling, the motion within each frame and the common coverage.

The origin is the first frame

Typical misconceptionAlignment gives back the true, undistorted specimen coordinates.

Better mental modelThe first recorded frame sets the origin and keeps its own distortion. The estimator is never given the absolute drift or the ideal specimen.

Run the experiment

  1. 01

    Record the frames first

    Load Recovery target, change the dwell time and confirm that the stored images do not change. Click Acquire next frames, then Estimate and align.

    What to observe: The acquisition controls set up the next stack. The search radius takes effect the next time the same counts are processed. The alignment toggle only changes what is displayed.
  2. 02

    Compare the set drift with the estimated shifts

    Reload Recovery target to restore the original dwell time. Use the two estimated components to work out the total shift, then compare it with Assigned first-to-last motion, which already shows a magnitude.

    What to observe: The Recovery target preset accepts all eight frames. Its estimated last-frame components are 5 and 2 nm, a total of about 5.4 nm, compared with the assigned 4.38 nm. Acceptance and correlation alone leave room for position error.
  3. 03

    Make the estimate fail

    Load Periodic ambiguity, No landmarks and Search too narrow. Read the number of frames used together with the common coverage. Then try Slow drifting scan and Interlaced scan.

    What to observe: A coverage of 100 percent can mean that only the reference frame was kept. Rejected frames are left out of the aligned average. A high image correlation does not prove that the shift is spatially accurate.
  4. 04

    Tell sampling apart from drift recovery

    Load Aliasing, reduce the pixel spacing to 2 nm, then acquire and process again.

    What to observe: The newly sampled grating has three pixels per period. The original stack can pass the shift checks while still showing an aliased grating.
Something broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy