minkowski_difference
Geometric functions minkowski_difference
syntax
- bp_minkowski_difference(polygon_data_item, kernel)
- bp_minkowski_difference(polygon_data_item, size, variant)
and the same two forms for bg_minkowski_difference, cgal_minkowski_difference and geos_minkowski_difference.
definition
The Minkowski difference (erosion) of a geometry A by a kernel K is the set of positions at which K fits entirely inside A. It shrinks A by the kernel’s shape, and it is what the old bp_polygon_d4HV family of operators did with twelve fixed kernels.
It is computed as
A (-) K = A \ ( (R \ A) (+) -K )
with R a box containing A with room to spare and -K the kernel reflected through the origin: eroding A is dilating everything outside it. All four backends use this identity, on top of their own minkowski_sum.
Since GeoDMS 20.18.0. See minkowski_sum for why the kernel became an argument, and Boost polygon functions for the migration table from the depreciated _d4HV … _dXD operators.
description
Everything in minkowski_sum about the two argument forms, the six variant names, the kernel restrictions and the four backends applies here unchanged, with one difference: this operator erodes, so it accepts the old d-prefixed variant spellings ('d4HV', 'd8D', …) and rejects an i prefix, naming minkowski_sum instead.
Erosion is not the inverse of dilation. Dilating and then eroding by the same kernel is the morphological closing: it fills notches narrower than the kernel and can only add, never remove, so the result always contains the original. Eroding and then dilating is the opening: it removes protrusions thinner than the kernel, and the result is always contained in the original. Neither round-trips back to where it started, which is exactly what makes them useful for cleaning up geometry.
Erosion can empty a feature: anything thinner than the kernel disappears, and a feature that vanishes entirely leaves an empty sequence rather than a null.
applies to
As minkowski_sum.
conditions
As minkowski_sum. In addition, the erosion works within a bounding box grown past the kernel’s reach, so a geometry whose coordinates already sit near the bp_ integer limit (2^25) has less headroom here than under minkowski_sum.
since version
20.18.0
examples
// shrink every parcel by 5 units, with a square kernel
attribute<ipoint> parcel_core (polygon, parcel) := bp_minkowski_difference(parcel/border, 5.0, '4HV');
// morphological opening: drop slivers thinner than 5 units, keep the rest in place
attribute<ipoint> opened (polygon, parcel) :=
bp_minkowski_sum(bp_minkowski_difference(parcel/border, 5.0, 'd4HV'), 5.0, 'i4HV');
// morphological closing: fill gaps narrower than 5 units
attribute<ipoint> closed (polygon, parcel) :=
bp_minkowski_difference(bp_minkowski_sum(parcel/border, 5.0, 'i4HV'), 5.0, 'd4HV');
see also
- minkowski_sum
- Boost polygon functions - the depreciated name-suffixed operators and what to write instead
- polygon deflated
- geos_buffer - a negative buffer distance also shrinks, with a round kernel