There are several grain-related algorithms implemented in Gwyddion. First of all, simple thresholding algorithms can be used (height, slope or curvature thresholding). These procedures can be very efficient namely within particle analysis (to mark particles located on flat surface).
Thresholding methods can be accessed within Gwyddion as → → . Height, slope and curvature thresholding is implemented within this module. The results of each individual thresholding methods can be merged together using several operators.
Similarly, the grains can be removed from the mask using → → menu choice. Maximum height and/or size thresholding methods can be used to eliminate false grains occurred by noise or some dust particles, for example. You can use also interactive grain removal tool for doing this manually.
For more complicated data structures the effectiveness of thresholding algorithms can be very poor. For these data a watershed algorithm can be used more effectively for grain or particle marking.
The watershed algorithm is usually employed for local minima determination and image segmentation in image processing. As the problem of determining the grain positions can be understood as the problem of finding local extremes on the surface this algorithm can be used also for purposes of grain segmentation or marking. For convenience in the following we will treat the data inverted in the z direction while describing the algorithm (i.e. the grain tops are forming local minima in the following text). We applied two stages of the grain analysis (see [1]):
In this way we can identify the grain positions and then determine the volume occupied by each grain separately.
Figure 4.18. Image of grain-like surface structure (a) and corresponding results of height thresholding (b), curvature thresholding (c), and watershed (d) algorithm. Within watershed algorithm it is possible to segment image even further.

Grain properties can be studied using several functions. The simplest of them is Grain Statistics
→ →
This function calculates the total number of marked grains, their total (projected) area both as an absolute value and as a fraction of total data field area, and the mean area and equivalent square size of one grain.
Overall characteristics of the marked area can be also obtained with Statistical Quantities tool when its Use mask option is switched on. By inverting the mask the same information can be obtained also for the non-grain area.
→ →
Grain Distributions is the most powerful and complex tool. It has two basic modes of operation: graph plotting and raw data export. In graph plotting mode selected characteristics of individual grains are calculated, gathered and summary graphs showing their distributions are plotted.
Raw data export is useful for experts who need for example to correlate properties of individual grains. In this mode selected grain characteristics are calculated and dumped to a text file table where each row corresponds to one grain and columns correspond to requested quantities. The order of the colums is the same as the relative order of the quantities in the dialog; all values are written in base SI units, as is usual in Gwyddion.
→ →
Grain correlation plots a graph of one selected graph quantity as the function of another grain quantity, visualizing correlations between them.
The grain measurement tool is the interactive method to obtain the same information about individual grains as Grain Distributions in raw mode. After selecting a grain on the data window with mouse, all the available quantities are displayed in the tool window.
Beside physical characteristics this tool also displays the grain number. Grain numbers corresponds to row numbers (counting from 1) in files exported by Grain Distributions.
Grain Distributions and Grain measurement tool can calculate the following grain properties:
The grain boundary length is estimated by summing estimated contributions of each pixel corner participating in the boundary. The contributions are displayed on the following figure for each type of corner configuration, where hx and hy are pixel dimension along corresponding axes and q is the length of the pixel diagonal.
Figure 4.20. Contributions of pixel configurations to the estimated boundary length. Grey squares represent pixels inside the grain, white squares represent outside pixels. The estimated contribution of each configuration is: (a) q/2, (b) q, (c) hy, (c) hx, (e) q/2.

The grain volume is, after subtracting the basis, estimated as the volume of exactly the same body whose upper surface is used for surface area calculation. Note for the volume between vertices this is equivalent to the classic two-dimensional trapezoid integration method. However, we calculate the volume under a mask centered on vertices, therefore their contribution to the integral is distributed differently as shown in the following figure.