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.
The automated Otsu's thresholding method is available as → → . This method classifies the data values into two classes, minimising the intra-class variances within both. It is most suitable for images that contain two relatively well defined value levels.
Another grain marking function, → → , is based on edge detection (local curvature). The image is processed with a difference-of-Gaussians filter of a given size and thresholding is then performed on this filtered image instead of the original.
Grains that touch image eges can be removed using → → menu choice. This is useful if such grains are considered incomplete and must be excluded from analysis. Several other other functions that may be useful for modification of grain shapes after marking are performed by the Mask Editor tool.
→ →
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. If features of interest are valleys rather than grains (hills), parameter Invert height can be used.
→ →
This function a different approach based on a watershed algorithm, in this case the classical Vincent algorithm for watershed in digital spaces [2], which is applied to a preprocessed image. Generally, the result is an image fully segmented to motifs, each pixel belonging to one or separating two of them. By default, the algorithm marks valleys. To mark upward grains, which is more common in AFM, use the opton Invert height.
The preprocessing has the following parameters:
Dispersion of Gaussian smoothing filter applied to the data. A zero value means no smoothing.
Relative weight of local gradient added to the data. Large values mean areas with large local slope tend to become grain boundaries.
Relative weight of local gradient added to the data. Large values mean locally concave areas with tend to become grain boundaries.
Relative height level above which pixels are never assigned to any grain. If not 100%, this creates an exception to the full-segmentation property.
Relative height level up to which the surface is prefilled, obliterating any details at the bottoms of deep valleys.
Relative height level up to which the surface is prefilled from each local minimum, obliterating any details at the bottoms of valleys.
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, total grain volumes, total length of grain boundaries and the mean area and equivalent square size of one grain. The mean size is calculated by averaging the equivalent square sides so its square is not, in general, equal to the mean area.
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 four-pixel configuration on the boundary. The contributions are displayed on the following figure for each type of configuration, where h_{x} and h_{y} are pixel dimension along corresponding axes and h is the length of the pixel diagonal:
The contributions correspond one-to-one to lengths of segments of the boundary of a polygon approximating the grain shape. The construction of the equivalent polygonal shape can also be seen in the figure.
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.
Curvature-related properties of individual grains are calculated identically to the global curvature calculated by Curvature. See its description for some discussion.
Inscribed discs and circumcircles of grains can be visualized using Selection Manager tool.
→ → and → → . These functions create circular selections representing the corresponding disc or circle for each grain that can be subsequently displayed usingMarked grains can be filtered by thresholding by any of the available grain quantities using
→ → menu choice. The module can be used for basic operations, such as removal of tiny grains using a pixel area threshold, as well as complex filtering using logical expressions involving several grain quantitities.
The filter retains grains that satisfy the condition specified as
Keep grains satisfying and removes all other
grains. The condition is expressed as a logical expression of one to
three individual thresholding conditions, denoted A
,
B
and C
. The simplest expression
is just A
, stating that quantity
A
must lie within given thresholds.
Each condition consits of lower and upper thresholds for one grain quantity, for instance pixel area or minimum value. The values must lie within the interval [lower,upper] to satisfy the condition and thus retain the grains. Note it is possible to choose the lower threshold larger than the upper threshold. In this case the condition is inverted, i.e. the grain is retained if the value lies outside [upper,lower].
Individual grain quantities are assigned to A
,
B
and C
by selecting the
quantity in the list and clicking on the corresponding button in
Set selected as. The currently selected set of
quantities is displayed in the
Condition A,
Condition B and
Condition C headers.
Grains can be aligned vertically using
→ → . This function vertically shifts each grain to make a certain height-related quantity of all grains equal. Typically, the grain minimum values are aligned but other choices are possible.Data between grains are also vertically shifted. The shifts are interpolated from the grain shifts using the Laplace equation, leading to a smooth transition of the shifts between the grains (though with no regard to other possible surface features).
The distance transform assigns to each pixel its distance to the grain (mask) boundary. It is, in a certain sense, complementary to the watershed. The distance transform can perform the transform using true Euclidean distance
as well as classical simple distances such as the city-block (4-neigbourhood)
and chessboard (8-neigbourhood)
distances that are useful mainly for didactic purposes. In addition, octagonal distances are available that are calculated by taking the cityblock and chessboard distance steps alternatively, obtaining ‘48’ and ‘84’ variants depending on which step is taken first. Finally, an octagonal distance without any specifier is available that is the average of the two variants.
If the transform is applied to grain interiors the distance is zero outside grains and increases towards the grain ‘centres’. Conversely, it can be applied to the exteriors and it is then highest for pixels farthest from any grain. It is also possible to calculate signed two-side transform which is the difference of the two transforms, i.e. it is positive inside grains and negative outside.
Option Shrink from border controls the handling of borders. When it is enabled, image boundaries are considerd to be also grain (or non-grain) boundaries. Pixels on the image edge thus cannot receive large values. When it is disabled, the grains (or non-grains) are effectively infinitely large outside the image. So pixels close to the boundary can receive large distance values.
[1] Petr Klapetek, Ivan Ohlídal, Daniel Franta, Alberto Montaigne-Ramil, Alberta Bonanni, David Stifter and Helmut Sitter: Acta Physica Slovaca, 3 (223-230) 2003
[2] Luc Vincent and Pierre Soille: IEEE Transactions on Pattern Analysis and Machine Intelligence, 13 (583–598) 1991