Skip to main content
Sandbox Physics

E09 · Electron acquisition / diffraction

Raster Scan & Drift Recovery

Can aligning repeated frames undo the distortion that drift causes in a scanned image? Only partly. Aligning frames on features that vary in both directions corrects the shift from one frame to the next. A featureless surface gives nothing to align on, and parallel stripes leave the shift along them undetermined. One shift per frame also cannot fix distortion that happens within a frame.

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{—}

Physics tutorial

Can recorded frames reveal their own drift?

BackgroundYou acquire a stack of fast frames, estimate from the recorded counts how far each frame has shifted, and compare the plain average with the aligned result. The motion the simulator actually applied is known, but it is used only as a separate check.

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.

Start with the essentials

Focus question
When can a shift be worked out from the images alone?
One-sentence intuition
Features that vary in two directions fix the shift in both directions. 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

    Compare the assigned first-to-last motion with the estimated horizontal and vertical shifts. Turn the alignment display off and on without acquiring again.

    What to observe: The estimated shifts come from image correlation, so they carry errors from count noise and from the model. They are measured relative to the first frame, and the motion within each frame is still there.
  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: Neither more frames nor interpolation can restore a grating that was undersampled. A shift estimate can pass even when the fine detail is aliased.
FeedbackSomething 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