Solution (source code)

= Solution

<AFM image flattening> estimates an unwanted background and subtracts it from the recorded height:
$$
z_{\rm corrected}(x,y)=z_{\rm measured}(x,y)-b(x,y).
$$
A plane removes overall tilt; a line-by-line constant or low-order fit removes line offsets or curvature. \b[For a tip-change height jump, align the baselines of unchanged reference regions on either side of the event], using a piecewise offset or appropriately masked line fits. A single global plane cannot in general remove an abrupt step.

Exclude genuine features from the fit, use the same terrace as a reference where possible, and retain the unprocessed data. The corrected image has a consistent relative background; it does not establish that the interaction <force>, tip shape or absolute height calibration remained unchanged. In particular, flattening is a correction for the offset component of a <tip-change artefact>, not a repair of every consequence of a changed tip.