Module Morph
See also

Aim of module

Applies morphological operations (opening, closing, erosion, dilation) on raster datasets.

General description

The morphological operations applied in this module are based on binary mathematical morphology. The basic idea in binary morphology is to probe an image with a simple, pre-defined shape, drawing conclusions on how this shape fits or misses the shapes in the image. This simple "probe" is called structuring element (or kernel), and is itself a binary image (i.e., a subset of the grid).
The basic operations are erosion and dilation. If we have a binary image A and the structuring element B that has a center, the erosion of A by B can be understood as the locus of points reached by the center of B when B moves inside A. If B has a center, as before, then the dilation of A by B can be understood as the locus of the points covered by B when the center of B moves inside A.
Opening implies erosion and dilation in this order, while closing consists of dilation and erosion applied in this order.
Opening by a disk rounds or eliminates all peaks extending into the images background (smoothing from inside) while closing by a disk rounds or eliminates all cavities extending into the image foreground.

Parameter description

-inFileinput file
Type: opals::Path
Remarks: mandatory
Raster image in GDAL supported format
-outFileoutput file
Type: opals::Path
Remarks: estimable
Morphologically filtered raster in GDAL supported format.
Estimation rule: The current directory and the name (body) of the input file are used as file name basis. Additionally, a postfix (containing the performed operation, kernel shape and size) and the extension according to the specified output format are constructed (e.g. '_dilate_circle_1.tif').
-oFormatraster file format [GTiff,AAIGrid,SCOP,...]
Type: opals::String
Remarks: estimable
Use GDAL driver names like GTiff, AAIGrid, USGSDEM, SCOP... .
Estimation rule: The output format is estimated based on the extension of the output file (*.tif->GTiff, *.dem->USGSDEM, *.dtm->SCOP...).
-operationmorphological operation
Type: opals::MorphOperation
Remarks: mandatory
Possible values:  
  erode .... morphological erosion filter
  dilate ... morphological dilation filter
  open ..... morphological opening filter
  close .... morphological closing filter
Morphological operation type: DILATE, ERODE, OPEN or CLOSE
-kernelShapekernel shape
Type: opals::KernelShape
Remarks: mandatory
Possible values:  
  square .... square kernel (Chebyshev metrics))
  circle .... circular kernel (Euclidean metrics)
  diamond ... diamond kernel (Manhattan metrics)
Kernel shape types refer to Manhattan (=Diamond), Euclidean (=Circle) orChebyshev (=Square) metrics
-kernelSizekernel size (radius of kernel in pixels)
Type: int32
Remarks: default=1
Kernel radius


  • The whole input raster must fit into the memory (RAM).


The data used in the following example are located in the$OPALS_ROOT/demo/ directory. For the strip 19 (contained in the demo directory) the following commands are required to obtain DSM model:

opalsImport -inFile strip21.laz
opalsGrid -inFile strip21.odm -outFile strip21.tif -inter movingPlanes -feature sigma0

As a result, a grid file strip21.tif in GeoTiff format is created. To obtain a binary grid of potential buildings areas we apply a simple thresholding to get morph_building.tif serving as input for the subsequent example.

opalsAlgebra -infile strip21.tif strip21_sigma0.tif -outfile morph_building.tif -formula "r[0]>275.5 && r[1]<0.1 ? 1 : 0"

Example 1:

In this example a morphological closing operation is applied on morph_building.tif dataset. The dataset is a binary GeoTiff grid:

Binarized grid: foreground (=white, valid) pixels are buildings, background (=black, invalid) pixels are non-buildings

For the Close operation the square-shaped kernel is applied with 1 pixel radius:

opalsMorph -inFile morph_building.tif -outFile morph_building_close_square_1.tif -operation CLOSE -kernelShape SQUARE -kernelSize 1

The output is written to a separate grid mask file in GeoTiff format (morph_building_close_square_1.tif) and is shown on the following figure:

The result of CLOSE operation: 'pepper noise' (single background pixels) are removed

Example 2:

We can also apply the Open operation on the previous image:

opalsMorph -inFile morph_building_close_square_1.tif -outFile morph_building_close_open_square_1.tif -operation OPEN -kernelShape SQUARE -kernelSize 1

The output is written to a separate grid mask file in GeoTiff format (morph_building_close_open_square_1.tif) and is shown on the following figure:

The result of OPEN operation: 'salt noise' (single foreground pixels) are removed


Hollaus, M., W. Wagner, G. Molnar, G. Mandlburger, C. Nothegger, J. Otepka (2010) Delineation of vegetation and building polygons from full-waveform airborne lidar data using OPALS software, Geospatial Data and Geovisualization: Environment, Security, and Society, Special Joint Symposium of ISPRS Technical Commission IV and AutoCarto 2010 in conjunction with ASPRS/GaGIS Speciality Conference, 15999 November 2010, Orlando, Florida, USA, CDROM, 7 p.

@ movingPlanes
moving (tilted) plane interpolation
@ sigma0
sigma 0 of grid post adjustment (i.e. of the unit weight observation)
Definition: GridFeature.hpp:12
opalsMorph is the executable file of Module Morph
Definition: ModuleExecutables.hpp:143
opalsAlgebra is the executable file of Module Algebra
Definition: ModuleExecutables.hpp:13
opalsImport is the executable file of Module Import
Definition: ModuleExecutables.hpp:113
@ kernelSize
output grid size equals entire kernel size
opalsGrid is the executable file of Module Grid
Definition: ModuleExecutables.hpp:93
@ feature
Use a statistic feature of the boundary gap points for filling.
@ formula
formula string for albegraic grid computations (opalsAlgebra)
@ operation
coordinate operation for crs transformations (opalsTranslate)