RSGISLib Image Morphology

Generate Operator

rsgislib.imagemorphology.create_circular_op(output_file: str, op_size: int)

Performs an image morphology dilate operation.

Parameters
  • output_file – is a string specifying the name and path of the output matrix file.

  • op_size – is a integer specifying the size of the operator.

import rsgislib.imagemorphology

rsgislib.imagemorphology.create_circular_op(output_file='CircularOp5.gmtxt', op_size=5)

Morphology Operations

rsgislib.imagemorphology.image_dilate(input_img: str, output_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology dilate operation.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

import rsgislib
import rsgislib.imagemorphology

inImg = 'clumpsImage.kea'
outImg = 'clumpsImage_Dilate.kea'

rsgislib.imagemorphology.image_dilate(input_img=inImg, output_img=outImg, morph_op_file=, use_op_file=False, op_size=5, gdalformat='KEA', datatype=rsgislib.TYPE_32UINT)
rsgislib.imagemorphology.image_dilate_combined_out(input_img: str, output_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology dilate operation, where the outputs will be combined into a single image.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_erode(input_img: str, output_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology erode operation.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_erode_combined_out(input_img: str, output_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology erode operation, where the outputs will be combined into a single image.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_gradiant(input_img: str, output_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology gradiant operation.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_gradiant_combined_out(input_img: str, output_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology gradiant operation, where the outputs will be combined into a single image.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_local_minima(input_img: str, output_img: str, sequencial_out: bool, allow_equal: bool, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Uses image morphology to find local minima.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • sequencial_out – is a boolean whether the output minima should be individual numbered (True) or just a binary mask (False).

  • allow_equal – is a boolean specifying whether equal values are allowed in the output.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_local_minima_combined_out(input_img: str, output_img: str, sequencial_out: bool, allow_equal: bool, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Uses image morphology to find local minima, where the outputs will be combined into a single image.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • sequencial_out – is a boolean whether the output minima should be individual numbered (True) or just a binary mask (False).

  • allow_equal – is a boolean specifying whether equal values are allowed in the output.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_opening(input_img: str, output_img: str, tmp_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int, niters: int)

Performs an image morphology opening operation.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • tmp_img – is a string specifying the name and path of a tempory file used for intermediate processing step(s). If empty string (‘’) then an in memory image will be used.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

  • niters – is an int for the number of iterations of the operators (Optional, default = 1)

rsgislib.imagemorphology.image_closing(input_img: str, output_img: str, tmp_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int, niters: int)

Performs an image morphology closing operation.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • tmp_img – is a string specifying the name and path of a tempory file used for intermediate processing step(s). If empty string (‘’) then an in memory image will be used.

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

  • niters – is an int for the number of iterations of the operators (Optional, default = 1)

rsgislib.imagemorphology.image_black_top_hat(input_img: str, output_img: str, tmp_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology black top hat operation.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • tmp_img – is a string specifying the name and path of a tempory file used for intermediate processing step(s).

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*

rsgislib.imagemorphology.image_white_top_hat(input_img: str, output_img: str, tmp_img: str, morph_op_file: str, use_op_file: bool, op_size: int, gdalformat: str, datatype: int)

Performs an image morphology white top hat operation.

Parameters
  • input_img – is a string specifying the name and path of the input file.

  • output_img – is a string specifying the name and path of the output file.

  • tmp_img – is a string specifying the name and path of a tempory file used for intermediate processing step(s).

  • morph_op_file – is a string with the name and path to a .gmtxt file with a square binary matrix specifying the morphology operator

  • use_op_file – is a boolean specifying whether the morph_op_file file is present or whether a square operator (specified via op_size) should be used. (True = morph_op_file, False = op_size)

  • op_size – is a integer specifying the square operator size (only used if use_op_file is False)

  • gdalformat – is a string specifying the GDAL image format (e.g., KEA)

  • datatype – is an int containing one of the values from rsgislib.TYPE_*