RSGISLib Image Filter

Contains image filtering functionality for rsgislib

Tiled (Multi Processing Core) Filtering

rsgislib.imagefilter.tiledfilter.perform_tiled_img_filter(input_img, output_img, filter_inst, datatype=None, gdalformat='KEA', tmp_dir='tmp', width=2000, height=2000, n_cores=-1)

This function will perform a filtering of an input image where the input image will be tiled and the tiles executed on multiple processing cores. This function is primarily of use for larger images or when using very large filter windows otherwise the over head of tiling and mosaicking are not worth it.

Parameters:
  • input_img – is the file name and path for the input image file.

  • output_img – is the file name and path for the output image file.

  • filter_inst – is an instance of a filter class available within rsgislib.imagefilter.tiledfilter.

  • datatype – is the output image data type (e.g., rsgislib.TYPE_32FLOAT; Default is None). If None then data type of input image is used.

  • gdalformat – string with the GDAL image format for the output image (Default = KEA). NOTE. KEA is used as intermediate format internally and therefore needs to be available.

  • tmp_dir – the temporary directory where intermediate files will be written (default is ‘tmp’). Directory will be created and deleted if does not exist.

  • width – int for width of the image tiles used for processing (Default = 2000).

  • height – int for height of the image tiles used for processing (Default = 2000).

  • n_cores – is an int specifying the number of cores to be used for processing.

import rsgislib
from rsgislib.imagefilter import tiledfilter
from rsgislib import imageutils

input_img = 'LandsatImg.kea'
output_img = 'LandsatImgMedianFilter.kea'

medianFilter = tiledfilter.RSGISMedianFilter(7, "KEA", rsgislib.TYPE_16UINT)
tiledfilter.perform_tiled_img_filter(input_img, output_img, medianFilter,
                                     width=2000, height=2000)
imageutils.pop_img_stats(output_img, False, 0, True)
rsgislib.imagefilter.tiledfilter.perform_tiled_img_multi_filter(input_img, output_imgs, filter_insts, datatype=None, gdalformat='KEA', tmp_dir='tmp', width=2000, height=2000, n_cores=-1)

This function will perform the filtering using multiple filters of an input image where the input image will be tiled and the tiles executed on multiple processing cores. This function is primarily of use for larger images or when using very large filter windows otherwise the over head of tiling and mosaicking are not worth it.

Parameters:
  • input_img – is the file name and path for the input image file.

  • output_imgs – is a list of file names and paths for the output image files - Note, must be the same length as filter_insts.

  • filter_insts – is a list of filter instances of the classes available within rsgislib.imagefilter.tiledfilter - Note, must be the same length as filter_insts.

  • datatype – is the output image data type (e.g., rsgislib.TYPE_32FLOAT; Default is None). If None then data type of input image is used.

  • gdalformat – string with the GDAL image format for the output image (Default = KEA). NOTE. KEA is used as intermediate format internally and therefore needs to be available.

  • tmp_dir – the temporary directory where intermediate files will be written (default is ‘tmp’). Directory will be created and deleted if does not exist.

  • width – int for width of the image tiles used for processing (Default = 2000).

  • height – int for height of the image tiles used for processing (Default = 2000).

  • n_cores – is an int specifying the number of cores to be used for processing.

import rsgislib
from rsgislib.imagefilter import tiledfilter
from rsgislib import imageutils

input_img = 'LandsatImg.kea'
outputImages = ['LandsatImgMedianFilter.kea', 'LandsatImgNormVarFilter.kea']

filters = [tiledfilter.RSGISMedianFilter(7, "KEA", rsgislib.TYPE_16UINT),
          tiledfilter.RSGISNormVarFilter(7, "KEA", rsgislib.TYPE_16UINT]
tiledfilter.perform_tiled_img_multi_filter(input_img, outputImages,
                                           filters, width=2000, height=2000)
imageutils.pop_img_stats(output_img, False, 0, True)
class rsgislib.imagefilter.tiledfilter.RSGISAbstractFilter

Abstract class for filter defining the interface to be used within the perform_tiled_img_filter function.

Parameters:
  • self.filter_size – size of the image filter (must be an odd number)

  • self.gdalformat – the output image file format

  • self.datatype – the output image data type (e.g., rsgislib.TYPE_16UINT)

abstract applyFilter(input_img, output_img)

Abstract function through which the input image is filtered to produce the output image.

Parameters:
  • input_img – is the name and path of the input image.

  • output_img – is the name and path of the output image.

getFilterHSize()

return the half size of the image filter (i.e., (filter_size-1)/2)

getFilterSize()

return the size of the image filter

Smoothing Filters

rsgislib.imagefilter.apply_median_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a median filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_median3.kea'
imagefilter.apply_median_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISMedianFilter(filter_size, gdalformat, datatype)

A class to apply a median filter

rsgislib.imagefilter.apply_mean_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a mean filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_mean3.kea'
imagefilter.apply_mean_filter(input_img, outImgFile, 3, "KEA",
                            rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISMeanFilter(filter_size, gdalformat, datatype)

A class to apply a mean filter

rsgislib.imagefilter.apply_gaussian_smooth_filter(input_img, output_img, filter_size, stddev_x, stddev_y, filter_angle, gdalformat, datatype)

Apply a Gaussian smoothing filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • stddev_x – standard deviation in the x-axis

  • stddev_y – standard deviation in the y-axis

  • filter_angle – the angle of the filter

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_gausmooth.kea'
imagefilter.apply_gaussian_smooth_filter(input_img, outImgFile, 3, 1.0, 1.0. 0.0,
                                      "KEA", rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISGaussianSmoothFilter(filter_size, stddev_x, stddev_y, filter_angle, gdalformat, datatype)

A class to apply a Gaussian smoothing filter

Edge Filters

rsgislib.imagefilter.apply_sobel_filter(input_img, output_img, gdalformat, datatype)

Apply a sobel filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_sobel.kea'
imagefilter.apply_sobel_filter(input_img, outImgFile, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISSobelFilter(gdalformat, datatype)

A class to apply a sobel filter

rsgislib.imagefilter.apply_sobel_x_filter(input_img, output_img, gdalformat, datatype)

Apply a sobel filter in X axis to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_sobelx.kea'
imagefilter.apply_sobel_x_filter(input_img, outImgFile, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISSobelXFilter(gdalformat, datatype)

A class to apply a sobel X filter

rsgislib.imagefilter.apply_sobel_y_filter(input_img, output_img, gdalformat, datatype)

Apply a sobel filter in Y axis to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_sobely.kea'
imagefilter.apply_sobel_y_filter(input_img, outImgFile, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISSobelYFilter(gdalformat, datatype)

A class to apply a sobel Y filter

rsgislib.imagefilter.apply_prewitt_filter(input_img, output_img, gdalformat, datatype)

Apply a Prewitt filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_prewitt.kea'
imagefilter.apply_prewitt_filter(input_img, outImgFile, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISPrewittFilter(gdalformat, datatype)

A class to apply a Prewitt filter

rsgislib.imagefilter.apply_prewitt_x_filter(input_img, output_img, gdalformat, datatype)

Apply a Prewitt filter in X axis to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_prewitt.kea'
imagefilter.apply_prewitt_x_filter(input_img, outImgFile, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISPrewittXFilter(gdalformat, datatype)

A class to apply a Prewitt X filter

rsgislib.imagefilter.apply_prewitt_y_filter(input_img, output_img, gdalformat, datatype)

Apply a Prewitt filter in Y axis to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_prewitt.kea'
imagefilter.apply_prewitt_y_filter(input_img, outImgFile, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISPrewittYFilter(gdalformat, datatype)

A class to apply a Prewitt Y filter

rsgislib.imagefilter.apply_gaussian_1st_deriv_filter(input_img, output_img, filter_size, stddev_x, stddev_y, filter_angle, gdalformat, datatype)

Apply a Gaussian first derivative filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • stddev_x – standard deviation in the x-axis

  • stddev_y – standard deviation in the y-axis

  • filter_angle – the angle of the filter

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_gau1st.kea'
imagefilter.apply_gaussian_1st_deriv_filter(input_img, outImgFile, 3, 1.0, 1.0. 0.0,
                                        "KEA", rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISGaussian1stDerivFilter(filter_size, stddev_x, stddev_y, filter_angle, gdalformat, datatype)

A class to apply a Gaussian first derivative filter

rsgislib.imagefilter.apply_gaussian_2nd_deriv_filter(input_img, output_img, filter_size, stddev_x, stddev_y, filter_angle, gdalformat, datatype)

Apply a Gaussian second derivative filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • stddev_x – standard deviation in the x-axis

  • stddev_y – standard deviation in the y-axis

  • filter_angle – the angle of the filter

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_gau1st.kea'
imagefilter.apply_gaussian_2nd_deriv_filter(input_img, outImgFile, 3, 1.0,
                                            1.0. 0.0, "KEA",
                                            rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISGaussian2ndDerivFilter(filter_size, stddev_x, stddev_y, filter_angle, gdalformat, datatype)

A class to apply a Gaussian second derivative filter

rsgislib.imagefilter.apply_laplacian_filter(input_img, output_img, filter_size, stddev, gdalformat, datatype)

Apply a Laplacian filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • stddev – standard deviation of the filter

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_laplacian.kea'
imagefilter.apply_laplacian_filter(input_img, outImgFile, 3, 1.0, "KEA",
                                   rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISLaplacianFilter(filter_size, stddev, gdalformat, datatype)

A class to apply a Laplacian filter

SAR Filters

rsgislib.imagefilter.apply_lee_filter(input_img, output_img, filter_size, n_looks, gdalformat, datatype)

Apply a Lee SAR filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • n_looks – int specifying the number of looks applied to the SAR image.

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_lee.kea'
imagefilter.apply_lee_filter(input_img, outImgFile, 3, 3, "KEA",
                             rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISLeeFilter(filter_size, n_looks, gdalformat, datatype)

A class to apply a SAR Lee filter

Statatics Filters

rsgislib.imagefilter.apply_min_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a min filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_min3.kea'
imagefilter.apply_min_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISMinFilter(filter_size, gdalformat, datatype)

A class to apply a min filter

rsgislib.imagefilter.apply_max_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a max filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_max3.kea'
imagefilter.apply_max_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISMaxFilter(filter_size, gdalformat, datatype)

A class to apply a max filter

rsgislib.imagefilter.apply_mode_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a mode filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_mode3.kea'
imagefilter.apply_mode_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISModeFilter(filter_size, gdalformat, datatype)

A class to apply a mode filter

rsgislib.imagefilter.apply_stddev_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a std dev filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_stdev3.kea'
imagefilter.apply_stddev_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISStdDevFilter(filter_size, gdalformat, datatype)

A class to apply a standard deviation filter

rsgislib.imagefilter.apply_range_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a range filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_range3.kea'
imagefilter.apply_range_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISRangeFilter(filter_size, gdalformat, datatype)

A class to apply a range filter

rsgislib.imagefilter.apply_coeff_of_var_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a coefficient of variance filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_cofvar3.kea'
imagefilter.apply_coeff_of_var_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISCoeffOfVarFilter(filter_size, gdalformat, datatype)

A class to apply a coefficient of variance filter

rsgislib.imagefilter.apply_total_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a total filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_total3.kea'
imagefilter.apply_total_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISTotalFilter(filter_size, gdalformat, datatype)

A class to apply a total filter

rsgislib.imagefilter.apply_norm_var_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a normalised variance filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_NormVar3.kea'
imagefilter.apply_norm_var_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISNormVarFilter(filter_size, gdalformat, datatype)

A class to apply a normalised variance filter

rsgislib.imagefilter.apply_norm_var_sqrt_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a normalised variance square root filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_NormVarSqrt3.kea'
imagefilter.apply_norm_var_sqrt_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISNormVarSqrtFilter(filter_size, gdalformat, datatype)

A class to apply a normalised variance square root filter

rsgislib.imagefilter.apply_norm_var_ln_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a normalised variance natural log filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_NormVarLn3.kea'
imagefilter.apply_norm_var_ln_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISNormVarLnFilter(filter_size, gdalformat, datatype)

A class to apply a normalised variance log filter

rsgislib.imagefilter.apply_texture_var_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a texture variance filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_NormVarLn3.kea'
imagefilter.apply_texture_var_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISTextureVarFilter(filter_size, gdalformat, datatype)

A class to apply a texture variance filter

rsgislib.imagefilter.apply_kuwahara_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a kuwahara filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_kuwa3.kea'
imagefilter.apply_kuwahara_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISKuwaharaFilter(filter_size, gdalformat, datatype)

A class to apply a kuwahara filter

rsgislib.imagefilter.apply_mean_diff_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a mean difference filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_meandiff3.kea'
imagefilter.apply_mean_diff_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISMeanDiffFilter(filter_size, gdalformat, datatype)

A class to apply a mean difference filter

rsgislib.imagefilter.apply_mean_diff_abs_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a mean absolute difference filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_meandiffabs3.kea'
imagefilter.apply_mean_diff_abs_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISMeanDiffAbsFilter(filter_size, gdalformat, datatype)

A class to apply a mean absolute difference filter

rsgislib.imagefilter.apply_total_diff_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a total (i.e., sum) difference filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_totaldiff3.kea'
imagefilter.apply_total_diff_filter(input_img, outImgFile, 3, "KEA",
                              rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISTotalDiffFilter(filter_size, gdalformat, datatype)

A class to apply a total difference filter

rsgislib.imagefilter.apply_total_diff_abs_filter(input_img, output_img, filter_size, gdalformat, datatype)

Apply a total absolute difference filter to the specified input image.

Parameters:
  • input_img – string specifying the input image to be filtered.

  • output_img – string specifying the output image file..

  • filter_size – int specifying the size of the image filter (must be an odd number, i.e., 3, 5, 7, etc).

  • gdalformat – string specifying the output image format (e.g., KEA).

  • datatype – Specifying the output image pixel data type (e.g., rsgislib.TYPE_32FLOAT).

import rsgislib
from rsgislib import imagefilter
input_img = 'jers1palsar_stack.kea'
outImgFile = 'jers1palsar_stack_totaldiffabs3.kea'
imagefilter.apply_total_diff_abs_filter(input_img, outImgFile, 3, "KEA",
                                        rsgislib.TYPE_32FLOAT)
class rsgislib.imagefilter.tiledfilter.RSGISTotalDiffAbsFilter(filter_size, gdalformat, datatype)

A class to apply a total absolution difference filter

Filter Banks

rsgislib.imagefilter.apply_filters(input_img, out_img_base, image_filters, gdalformat, out_img_ext, datatype)

Filters images

Parameters:
  • input_img – is a string containing the name of the input image

  • out_img_base – is a string containing the base name of the output images

  • image_filters – is list of rsgislib.imagefilter.FilterParameters objects providing the type of filter and required parameters (see example)

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • out_img_ext – is a string with the output image file extention (e.g., kea):param datatype: is an int containing one of the values from rsgislib.TYPE_*

import rsgislib
from rsgislib import imagefilter
inputImage = './Rasters/injune_p142_casi_sub_utm_single_band.vrt'
outputImageBase = './TestOutputs/injune_p142_casi_sub_utm_single_band'
gdalformat = 'KEA'
outExt = 'kea'
datatype = rsgislib.TYPE_32FLOAT
filters = []
filters.append(imagefilter.FilterParameters(filterType = 'GaussianSmooth', fileEnding = 'gausmooth', size=3, stddevX = 1., stddevY = 1, angle = 0.) )
filters.append(imagefilter.FilterParameters(filterType = 'Gaussian1st', fileEnding = 'gau1st', size=3, stddevX = 1., stddevY = 1, angle = 0.) )
filters.append(imagefilter.FilterParameters(filterType = 'Gaussian2nd', fileEnding = 'gau1st', size=3, stddevX = 1., stddevY = 1, angle = 0.) )
filters.append(imagefilter.FilterParameters(filterType = 'Laplacian', fileEnding = 'laplacian', size=3, stddev = 1) )
filters.append(imagefilter.FilterParameters(filterType = 'Sobel', fileEnding = 'sobelx', option = 'x') )
filters.append(imagefilter.FilterParameters(filterType = 'Sobel', fileEnding = 'sobely', option = 'y') )
filters.append(imagefilter.FilterParameters(filterType = 'Sobel', fileEnding = 'sobelxy', option = 'xy') )
filters.append(imagefilter.FilterParameters(filterType = 'Prewitt', fileEnding = 'prewittx', option = 'x') )
filters.append(imagefilter.FilterParameters(filterType = 'Prewitt', fileEnding = 'prewitty', option = 'y') )
filters.append(imagefilter.FilterParameters(filterType = 'Prewitt', fileEnding = 'prewittxy', option = 'xy') )
filters.append(imagefilter.FilterParameters(filterType = 'Mean', fileEnding = 'mean', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Median', fileEnding = 'median', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Mode', fileEnding = 'mode', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'StdDev', fileEnding = 'stddev', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Range', fileEnding = 'range', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'CoeffOfVar', fileEnding = 'coeffofvar', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Min', fileEnding = 'min', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Max', fileEnding = 'max', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Total', fileEnding = 'total', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'MeanDiff', fileEnding = 'meandiff', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'MeanDiffAbs', fileEnding = 'meandiffabs', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'TotalDiff', fileEnding = 'meandiff', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'TotalDiffAbs', fileEnding = 'meandiffabs', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Kuwahara', fileEnding = 'kuwahara', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'Lee', fileEnding = 'lee', size=3, nLooks=3) )
filters.append(imagefilter.FilterParameters(filterType = 'NormVar', fileEnding = 'normvar', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'NormVarSqrt', fileEnding = 'normvarsqrt', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'NormVarLn', fileEnding = 'normvarln', size=3) )
filters.append(imagefilter.FilterParameters(filterType = 'TextureVar', fileEnding = 'texturevar', size=3) )
# Apply filters
imagefilter.apply_filters(inputImage, outputImageBase, filters, gdalformat, outExt, datatype)
rsgislib.imagefilter.leung_malik_filter_bank()

imagefilter.(input_img, out_img_base, gdalformat, out_img_ext, datatype) Implements the Leung-Malik filter bank described in: Leung, T., Malik, J., 2001. Representing and recognizing the visual appearance of materials using three-dimensional textons. International Journal of Computer Vision 43 (1), 29-44.

Parameters:
  • input_img – is a string containing the name of the input image

  • out_img_base – is a string containing the base name of the output images

  • gdalformat – is a string containing the GDAL format for the output file - eg ‘KEA’

  • out_img_ext – is a string with the output image file extention (e.g., kea):param datatype: is an int containing one of the values from rsgislib.TYPE_*

import rsgislib
from rsgislib import imagefilter
inputImage = './Rasters/injune_p142_casi_sub_utm_single_band.vrt'
outputImageBase = './TestOutputs/injune_p142_casi_sub_utm_single_band'
gdalformat = 'KEA'
outExt = 'kea'
datatype = rsgislib.TYPE_32FLOAT
imagefilter.leung_malik_filter_bank(inputImage, outputImageBase, gdalformat, outExt, datatype)