Data Leveling and Background Subtraction


The data obtained from SPM microscopes are very often not leveled at all; the microscope directly outputs raw data values computed from piezoscanner voltage, strain gauge, interferometer or other detection system values. This way of exporting data enables the user to choose his/her own method of leveling data.

The choice of leveling method should be based on your SPM system configuration. Basically, for systems with independent scanner(s) for each axis, plane leveling should be sufficient. For systems with scanner(s) moving in all three axes (tube scanners) 2nd order polynomial leveling should be used.

Of course, you can use higher order leveling for any data, however, this can supress real features on the surface (namely waviness of the surface) and therefore alter the statistical functions and quantities evaluated from the surface.

Fix Zero and Zero Mean Value

Data ProcessLevelFix Zero

Data ProcessLevelZero Mean Value

The simplest functions that are connected with data leveling are Fix Zero and Zero Mean Value that just add a constant to all the data to move the minimum and mean value to zero, respectively.

Plane Level

Data ProcessLevelPlane Level

Plane leveling is usually one of the first functions applied to raw SPM data. The plane is computed from all the image points and is subtracted from the data.

If a mask is present plane leveling offers to use the data under mask for the plane fitting, exclude the data under mask or ignore the mask and use the entire data.


You can quickly apply plane leveling by simply right-clicking on the image window and selecting Level.

Three Point Leveling Tool

The Three Point Leveling tool can be used for leveling very complicated surface structures. The user can simply mark three points in the image that should be at the same level, and then click Apply. The plane is computed from these three points and is subtracted from the data.

Facet Level

Data ProcessLevelFacet Level

Facet Level levels data by subtracting a plane similarly to the standard Plane Level function. However, the plane is determined differently: it makes facets of the surface as horizontal as possible. Thus for surfaces with flat horizontal areas it leads to much better results than the standard Plane Level especially if large objects are present.

On the other hand, it is not suitable for some types of surface. These includes random surfaces, data with considerable fine noise and non-topographic images as the method does not work well if the typical lateral dimensions and heights differ by many orders.

Similarly to Plane Level, Facet Level can include or exclude the data under mask. This choice is offered only if a mask is present.

Finding the orientation of the facets is an iterative process that works as follows. First, the variation of local normals is determined:

where ni is the vector of local facet normal (see inclination coordinates) in the i-th pixel. Then the prevalent normal is estimated as

where c = 1/20 is a constant. Subsequently, the plane corresponding to the prevalent normal n is subtracted and these three steps are repeated until the process converges. The gaussian weighting factors serve to pick a single set of similar local facet normals and converge to their mean direction. Without these factors, the procedure would obviously converge in one step to the overall mean normal – and hence would be completely equivalent to plain plane leveling.

Facet Level example: (a) uncorrected, sloping data; (b) data leveled by standard plane fitting (Plane Level); (c) data leveled by Facet Level.

Level Rotate

Data ProcessLevelLevel Rotate

Level Rotate behaves similarly to Plane Level, however it does not simply subtract the fitted plane from the data. Instead, this module takes the fitted plane parameters and rotates the image data by a calculated amount to make it lie in a plane. So unlike Plane Level, this module should therefore preserve angle data in the image.

Background Subtraction

Gwyddion has several special modules for background subtraction. All allow you to extract the subtracted background to a separate data window.


For finer control, you can use any of Gwyddion's filtering tools on an image, and then use the Data Arithmetic module to subtract the results from your original image.

Polynomial Background

Data ProcessLevelPolynomial Background

Fits data by a polynomial of the given order and subtracts this polynomial. In the Independent degree mode the horizontal and vertical polynomial orders can be generally set separately, i.e. the fitted polynomial is

2D polynomial expression with independent maximum x and y degrees

where m and n are the selected horizontal and vertical polynomial degrees, respectively. In the Limited total degree mode the fitted polynomial is

2D polynomial expression with limited total degree

where n is the selected total polynomial degree.

Similarly to Plane Level, polynomial background subtraction can include or exclude the data under mask. This choice is offered only if a mask is present.

Flatten base

Data ProcessLevelFlatten Base

When a number of large features are present on a flat base surface the combination of masking, plane, facet and/or polynomial levelling can be used to level the flat base. It can require, however, several steps and trial and error parameter adjustment. Flatten Base attempts to perform this levelling automatically using a combination of facet and polynomial levelling with automated masking. It attempts to maximise the sharpness of the height distribution peak corresponding to the flat base surface.

Flatten Base example: original image, levelled using Facet Level, levelled using Plane Level, levelled using Flatten Base. The original image is shown in linear colour scale, the levelled images are shown in adaptive colour scale. The graph below each image shows the corresponding height distribution (with the same axis ranges).

Revolve Arc

Data ProcessLevelRevolve Arc

Data are levelled by revolving a virtual arc of given radius horizontally or vertically over (or under) the data. The envelope of this arc is treated as a background, resulting in removal of features larger than the arc radius (approximately). It is also possible to apply the levelling in both directions – in this case the arc is first revolved horizontally, then vertically.

Revolve Sphere

Data ProcessLevelRevolve Sphere

Data are levelled by revolving a virtual sphere of given over (or under) the data. The envelope of this sphere is treated as a background, resulting in removal of features larger than the sphere radius (approximately).


This operation can be very slow for large sphere radii.

Median Level

Data ProcessLevelMedian Level

Filters data with a median filter using a large kernel and treats the result as background. Only features smaller than approximately the kernel size will be kept.


This operation can be very slow for large kernels.


Data ProcessLevelCurvature

The global surface curvature parameters are calculated by fitting a quadratic polynomial and finding its main axes. Positive signs of the curvature radii correspond to a concave (cup-like) surface, whereas negative signs to convex (cap-like) surface, mixed signs mean a saddle-like surface.

Beside the parameter table, it is possible to set the line selection on the data to the fitted quadratic surface axes and/or directly read profiles along them. The zero of the abscissa is placed to the intersection of the axes.

Similarly to the background subtraction functions, if a mask is present on the data the module offers to include or exclude the data under mask.

Curvature dialog screenshot showing the strong deflection of a glass plate with a thin film with compressive internal stress.

Fit Shape

Data ProcessLevelFit Shape

Form removal as well as measurement of geometrical parameters can be performed by fitting geometrical shapes on the data using the least-squares method. The Fit Shape module is essentially the same for images and XYZ data and it is described in detail in the XYZ data processing part. Only the differences are mentioned here.

Standard masking is supported for images. That is if a mask is present the dialog offers to use the data under the mask, exclude the data under mask or ignore the mask and use the entire data. Since the excluded pixels can be outliers or image parts not conforming to the chosen shape it it possible to avoid them also in the difference image by disabling Calculate differences for excluded pixels.