xrspatial.morphology.morph_opening#
- xrspatial.morphology.morph_opening(agg, kernel=None, boundary='nan', name='opening')[source]#
Apply morphological opening (erosion then dilation) to a 2D raster.
Opening removes small bright features and salt noise while preserving the overall shape of larger structures.
- Parameters:
agg (xarray.DataArray) – 2D raster of numeric values.
kernel (numpy.ndarray or None) – 2D structuring element with odd dimensions. Defaults to a 3x3 square.
boundary (str, default
'nan') – Edge handling:'nan','nearest','reflect', or'wrap'.name (str, default
'opening') – Name for the output DataArray.
- Returns:
Opened raster.
- Return type:
xarray.DataArray
Examples
>>> from xrspatial.morphology import morph_opening >>> cleaned = morph_opening(binary_mask)