The mask-related functions can be divided into three main groups:
Masks are created by various types of marking functions, namely grain marking functions (Mark by Threshold, Mark by Watershed), defect marking functions (Mask of Outliers, Mark Scars) and feature marking functions (Mask by Correlation, Facet Analysis, Certainty Map). In addition, some general mask editing functions provide means to create masks from scratch.
Masks are also used to mark invalid pixels in files imported from formats that distinguish between valid and invalid pixels since Gwyddion does not have a concept of invalid pixels.
In general, the mask-covered area is considered to be the area of interest, i.e. the area to operate on. This applies namely to statistical functions such as the Statistical Quantities tool. Function Interpolate Data Under Mask replaces the data under mask, while the Remove Grains tool can perform such replacement for individual grains. There are several functions for the examination of grain properties, see section Grain Statistics.
Some functions ask whether to consider the area under mask included or excluded (or ignore the mask), namely levelling functions. Such choice is offered only if a mask is present on the data.
A few basic mask operations, such as inversion or complete removal, are available in Remove Grains tool and Grain Filter that provide different means to remove parts of the mask, as well as Mask Editor tool and Mark With focused on general mask editing.→ menu. More advanced functions include the grain-oriented
This section describes general mask functions that are not tied to specific applications.
Functioncreates a new image from the mask of the current image. The image will have values 1 in masked pixels and 0 in unmasked pixels.
Mask can be shifted horizontally and/or vertically using Exterior type controls how they are filled. The periodic, mirror and border-copying methods work the same as in Extend. In addition all the outside pixels can be set to masked (Filled) or unmasked (Empty).→ → . After shifting the mask, some its pixels correspond to outside of the image. The
Occasionally it is useful to copy a mask to many images. This can be done using the Preserve existing masks is enabled the function avoids replacing existing masks. Note that the mask can be copied only to images with the same pixel dimensions. Hence images with different dimensions are automatically excluded.function. It can copy the mask either to all images within one file or all images in all open files. If the checkbox
The Mask Editor tool is the “Swiss Army knife” for mask modification. It provides two groups of functions: editing of the mask by drawing directly in the data window and global operations with the mask such as inversion or growing and shrinking.
The direct mask modification is controlled by the buttons in the Editor group. It can be done in two ways: by selecting geometrical shapes that are subsequently filled or erased (using the Shapes option), and by freehand drawing operations using drawing tools (option Drawing Tools).
Buttons in the Mode row select how the geometrical shape drawn in the data window will modify the mask:
The mask is set to the drawn shape, discarding any mask already present.
The mask is extended by the drawn shape (if there is no mask yet a mask is created).
The drawn shape is cut out from the mask This function has no effect if there is no mask.
The mask is set to the intersection of the drawn shape and the already present mask. This function has no effect if there is no mask.
Buttons in the Shape row control which shape is drawn on the mask. The choices include rectangles, ellipses and thin lines.
Freehand drawing tools are selected by buttons in the Tool row:
Freehand drawing with a pencil of radius specified by parameter Radius. Note this may be slow on slow computers and/or large data fields.
Freehand erasing with an eraser of radius specified by parameter Radius. Note this may be slow on slow computers and/or large data fields.
Bucket-filling of a contiguous unmasked area.
Bucket erase-filling of a contiguous masked area.
The basic global operation with masks, i.e. inversion, removal and filling the entire data field area with a mask are available in the Actions row. Additional operations include:
Extends the mask by Amount pixels on each side. More precisely, the mask is extended by one pixel on each side and this is repeated Amount times.
Normally, growing does not distinguish between individual parts of the mask. Parts that grow so much that they touch therefore merge. This can be prevented by Prevent grain merging by growing which makes individual parts of the mask stop growing once there is only one-pixel space between them.
When the mask is extended by a large amount it can become important how exactly we measure the distance from the mask edge because it essentially determines the shape to which small grains will grow. This is controlled by option Distance type. The various distance types are described in paragraph Distance Transform. Usually, the Euclidean distance is preferable.
Reduces the mask by Amount pixels from each side. More precisely, the mask is reduced by one pixel from each side and this is repeated Amount times.
The reduction may or may not occur from the data field borders. This is controlled by the Shrink from border check box. Similar to growing, it is possible to specify the distance type also for shrinking.
Makes the grains simply-connected, i.e. without any holes, by filling the holes in grains. The checkbox Fill non-simple-connected controls if only simple holes are filled, i.e. holes that are themselves simply-connected, or all holes are filled, regardless of topology.
Mark With can create or modify masks using another mask or data of the same dimensions. The operations that can be applied to the current mask are the same as in the Mask Editor tool: creation, union, subtraction and intersection. The source of the other mask can be one of the following:
This is the simplest case, a mask can be combined with another mask using the specified logical operations.
In the Data mode, another height field is used as the other mask source. The mask consists of pixels within a range of heights, specified as relative values within the total range. To use pixels outside a certain range for the masking, set the upper bound to a smaller value than the lower bound.
The Presentation mode differs from Data mode only in that a presentation is used instead of the data.
This is an exception to the rule stating that presentations are never used for further processing. Sometimes it can be useful to mark, for instance, edges found on the data even though the corresponding presentation visualizes a quantity weird from the physical point of view.
Classical morphological operations can be performed with masks using→ → . All the operations take the mask as one operand and so-called structuring element as the second operand that determines the precise effect. The structuring element can be chosen from a few predefined basic shapes (disc, octagon, square, diamond) or it can be given as another mask.
The basic shapes are all symmetrical. When another mask is used as the structuring element it may be asymmetrical or have empty borders. In this case the structuring element has the full dimensions of the selected mask image, including any empty borders. This full-size image is considered centred. If you want to remove empty borders from the structuring elements mask, enable the option Trim empty border. The structuring element will be then again centred but after the empty border removal.
The available operations include:
Erosion removes small features and reduces the size or larger features – by amount and shape given by the structuring element. More precisely, if the structuring element is placed to a pixel of the mask and it is entirely contained in the mask then such pixel is kept in the mask. All other mask pixels are cleared.
Dilation fills small holes and increases the size of features – by amount and shape given by the structuring element. More precisely, if the structuring element is rotated by 180 degrees and placed to each pixel of the mask the result of dilation is the union of all these shifted structuring elements.
Opening is erosion followed by dilation. The dilation corrects the effect of the preceding erosion where the mask conforms to the structuring elements. The net effect is that small non-conforming bumps and grains are removed but conforming parts are kept intact. The mask shape is thus cleaned and simplified.
Closing is dilation followed by erosion. The erosion corrects the effect of the preceding dilation where the mask conforms to the structuring elements. The net effect is that small non-conforming holes and dents are removed but conforming parts are kept intact. The mask shape is thus simplified.
A simple opening or closing filter may be too rough for correction of shape flaws of varying sizes. The alternating sequential filter consists of a sequence of closing and opening operations with progressively increasing structuring elements up to the given size and preserves better the shape of features that should not be removed by the opening. The final operation of this filter is the opening.
A simple opening or closing filter may be too rough for correction of shape flaws of varying sizes. The alternating sequential filter consists of a sequence of opening and closing operations with progressively increasing structuring elements up to the given size and preserves better the shape of features that should not be removed by the closing. The final operation of this filter is the closing.
The distance transform assigns to each pixel its distance to the mask boundary. It is available as watershed. The distance transform can perform the transform using true Euclidean distance→ → . This operation is, in a certain sense, complementary to the
as well as classical simple distances such as the city-block (4-neighbourhood)
and chessboard (8-neighbourhood)
distances that are useful mainly for didactic purposes. In addition, octagonal distances are available that are calculated by taking the city-block 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 considered 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.
Thinning is another classical morphological operation, available as→ → . It reduces the mask to a skeleton consisting only of thin lines characterizing the overall shape. If the mask boundary is jagged thinning can result in a large number of extra strands. Therefore it is often useful to apply a simplifying operation beforehand (opening or closing).
It should be noted that this function works only with the mask. It does not use any information from the underlying height field. Therefore, even though the thinned mask can often coincide with summits and ridges of marked topographical features, this is generally just a coincidence.
Function→ → adds random salt and/or pepper noise to the mask, as selected by the noise type (symmetrical, positive or negative). This is useful mainly for the evaluation and development of data processing methods.
Parameter Density determines the fraction of image pixels touched. If Alter only boundaries is enabled a mask pixels is not changed unless it is currently at the boundary, i.e. some of its 4-neighbours differs from the pixel.