Spatial morphological Binary Opening filter

Spatial morphological Binary Opening filter. See Wikipedia for general information.

The filter operates by first applying a binary erosion operation to the input image using a structuring element, which is a predefined shape. The erosion operation removes small 1 regions and shrinks the remaining regions.

Next, a binary dilation operation is applied to the eroded image using the same structuring element. The dilation operation expands the remaining regions, counteracting the shrinkage caused by the erosion operation. The result is a binary image where small foreground regions have been eliminated, and the remaining regions have been smoothed and preserved.

When applying this algorithm to continous image data, the input will be binarised.

Usage:

  1. Start the algorithm from the Processing Toolbox panel.

  2. Select the raster to process and modify the parameterization if necessary, then click run.

    ../../../../_images/binary_opening_filter_interface.png
  3. Processed image in comparison to the original.

    ../../../../_images/binary_opening_filter_result.png

Parameters

Raster layer [raster]

Raster layer to be processed band-wise.

Function [string]

Python code. See binary_closing, generate_binary_structure, iterate_structure for information on different parameters.

Default:

from scipy.ndimage import binary_opening, generate_binary_structure, iterate_structure

structure = generate_binary_structure(rank=2, connectivity=1)
structure = iterate_structure(structure=structure, iterations=1)
function = lambda array: binary_opening(array, structure=structure, iterations=1)

Outputs

Output raster layer [rasterDestination]

Raster file destination.

Command-line usage

>qgis_process help enmapbox:SpatialMorphologicalBinaryOpeningFilter:

----------------
Arguments
----------------

raster: Raster layer
    Argument type:  raster
    Acceptable values:
            - Path to a raster layer
function: Function
    Default value:  from scipy.ndimage import binary_opening, generate_binary_structure, iterate_structure

structure = generate_binary_structure(rank=2, connectivity=1)
structure = iterate_structure(structure=structure, iterations=1)
function = lambda array: binary_opening(array, structure=structure, iterations=1)
    Argument type:  string
    Acceptable values:
            - String value
            - field:FIELD_NAME to use a data defined value taken from the FIELD_NAME field
            - expression:SOME EXPRESSION to use a data defined value calculated using a custom QGIS expression
outputRaster: Output raster layer
    Argument type:  rasterDestination
    Acceptable values:
            - Path for new raster layer

----------------
Outputs
----------------

outputRaster: <outputRaster>
    Output raster layer