## Distance transform

Distance transform — Distance transform and related morphological operations

## Functions

const GwyEnum * | gwy_distance_transform_type_get_enum ()
void | gwy_nield_distance_transform ()
void | gwy_nield_shrink ()
void | gwy_nield_grow ()
void | gwy_nield_thin ()

## Types and Values

enum | GwyDistanceTransformType

## Includes

    #include <libgwyddion/gwyddion.h>

## Description

## Functions

### gwy_distance_transform_type_get_enum()

    const GwyEnum *
    gwy_distance_transform_type_get_enum (void);

Returns GwyEnum for GwyDistanceTransformType enum type.

#### Returns

`NULL`-terminated GwyEnum which must not be modified nor freed.

### gwy_nield_distance_transform()

    void
    gwy_nield_distance_transform (GwyNield *nield,
                                  GwyField *distances,
                                  GwyDistanceTransformType dtype,
                                  gboolean merged,
                                  gboolean from_border);

Performs a distance transform of a number field.

For each non-zero value, a distance to the grain boundary is calculated, measured in pixels. For unmarked pixels in `nield` , the distance is set to zero.

If `merged` is TRUE, there is no boundary between touching grains. The distance is calculated from unmarked area (and possibly from image edges). If `merged` is `FALSE`, regions filled with different numbers in `nield` are considered individually, creating boundaries also where different grains touch.

If the entire `nield` is marked, `from_border` is `FALSE` and either `merged` is `TRUE` or `nield` is filled with the same value, there are no boundaries to calculate the distance from. In such case `distances` is filled with a huge positive value (like `G_MAXDOUBLE`).

#### Parameters

nield | A number field with zeros in empty space and nonzeros in marked areas. |
distances | Output data field which will be resized and filled with the distances. |
dtype | Type of simple distance to use. |
merged | `TRUE` to only distinguish marked/unmarked; `FALSE` to distinuish grain numbers. |
from_border | `TRUE` to consider image edges to be grain boundaries. |

### gwy_nield_shrink()

    void
    gwy_nield_shrink (GwyNield *nield,
                      gdouble amount,
                      GwyDistanceTransformType dtype,
                      gboolean merged,
                      gboolean from_border);

Erodes a number field containing mask by specified amount using a distance measure.

Non-zero pixels in `nield` will be replaced with zeros if they are not farther than `amount` from the grain boundary as defined by `dtype` .

#### Parameters

nield | A number field with zeros in empty space and nonzeros in grains. |
amount | How much the grains should be reduced, in pixels. It is inclusive, i.e. pixels that are `amount` far from the border will be removed. |
dtype | Type of simple distance to use. |
merged | `TRUE` to only distinguish marked/unmarked; `FALSE` to distinuish grain numbers. |
from_border | `TRUE` to consider image edges to be grain boundaries. `FALSE` to reduce grains touching field boundaries only along the boundaries. |

### gwy_nield_grow()

    void
    gwy_nield_grow (GwyNield *nield,
                    gdouble amount,
                    GwyDistanceTransformType dtype,
                    gboolean prevent_touching);

Dilates a number field containing mask by specified amount using a distance measure.

Non-positive pixels in `field` will be replaced with ones if they are not farther than `amount` from the grain boundary as defined by `dtype` .

#### Parameters

nield | A number field with zeros in empty space and nonzeros in grains. |
amount | How much the grains should be expanded, in pixels. It is inclusive, i.e. exterior pixels that are `amount` far from the border will be filled. |
dtype | Type of simple distance to use. |
prevent_touching | `TRUE` to prevent grain touching, i.e. the growth stops where two grains would touch. `FALSE` to simply expand the grains, without regard to grain connectivity. |

### gwy_nield_thin()

    void
    gwy_nield_thin (GwyNield *nield);

Performs thinning of a data field containing mask.

The result of thinning is a ‘skeleton’ mask consisting of single-pixel thin lines.

#### Parameters

nield | A number field with zeros in empty space and nonzeros in grains. |

## Types and Values

### enum GwyDistanceTransformType

Type of distance transform.

#### Members

GWY_DISTANCE_TRANSFORM_CITYBLOCK | City-block distance (sum of horizontal and vertical distances). |
GWY_DISTANCE_TRANSFORM_CONN4 | Four-connectivity distance; another name for city-block distance. |
GWY_DISTANCE_TRANSFORM_CHESS | Chessboard distance (maximum of horizontal and vertical distance). |
GWY_DISTANCE_TRANSFORM_CONN8 | Eight-connectivity distance; another name for chessboard distance. |
GWY_DISTANCE_TRANSFORM_OCTAGONAL48 | Octagonal distance beginning from city-block. |
GWY_DISTANCE_TRANSFORM_OCTAGONAL84 | Octagonal distance beginning from chess. |
GWY_DISTANCE_TRANSFORM_OCTAGONAL | Average octagonal distance, i.e. the mean of the 48 and 84 distances. |
GWY_DISTANCE_TRANSFORM_EUCLIDEAN | True Euclidean distance. |