Filtering

class eolab.georastertools.Filtering(raster_filter: RasterFilter, kernel_size: int, bands: List[int] = [1])[source]

Bases: Rastertool, Windowable

Raster tool that applies a filter on a raster image.

Predefined filters are available:

  • Median filter

  • Local sum

  • Local mean

  • Adaptive gaussian filter.

A filter is applied on a kernel of a configurable size. To set the kernel size, you need to call:

tool = Filtering(Filtering.median_filter, kernel_size=16)

Custom additional filters can be easily added by instanciating a RasterFilter (see eolab.georastertools.processing.RasterFilter).

The parameters that customize the filter algo can be passed by following this procedure:

def myalgo(input_data, **kwargs):
    # kwargs contain the values of the algo parameters
    kernel_size = kwargs.get('kernel_size', 8)
    myparam = kwargs.get('myparam', 1)
    # ... do someting ...

my_filter = RasterFilter(
    "myfilter", algo=myalgo
).with_documentation(
    help="Apply my filter",
    description="Apply my filter"
).with_arguments({
    "myparam": {
        # configure the command line interface for this param, this can be skipped
        "default": 8,
        "required": True,
        "type": int,
        "help": "my configuration param for myalgo"
    }
})

# create the raster tool
tool = Filtering(my_filter, kernel_size=16)
my_filter.with_output(".")
my_filter.with_window(1024, "edge")
# set the configuration parameter of the algo
my_filter.with_filter_configuration({"myparam": 1024})
# run the tool
tool.process_file("./mytif.tif")

Attributes

Filtering.adaptive_gaussian

RasterFilter that applies an adaptive gaussian filter to the kernel.

Filtering.bands

List of bands to process

Filtering.keep_vrt

Whether intermediate VRT images shall be kept

Filtering.local_mean

Computes the local means of the input data.

Filtering.local_sum

Computes the local sums of the input data.

Filtering.median_filter

Applies a Median Filter to the input data using scipy.ndimage.median_filter.

Filtering.outputdir

Path of the output directory where are stored the results

Filtering.pad_mode

//numpy.org/doc/stable/reference/generated/numpy.pad.html>`_ the image when the window is on the edge of the image The mode can be self defined or among [constant (default), edge, linear_ramp, maximum, mean, median, minimum, reflect, symmetric, wrap, empty].

Filtering.raster_filter

Name of the filter to apply to the raster

Filtering.vrt_dir

Dir where to store intermediate VRT images

Filtering.window_size

Size of the windows to split the image in small parts

Methods

Filtering.__init__(raster_filter, kernel_size)

Constructor

Filtering.get_default_filters()

Get the list of predefined raster filters

Filtering.postprocess_files(inputfiles, ...)

Run a postprocess when all input files have been processed.

Filtering.process_file(inputfile)

Apply the filter to the input file

Filtering.process_files(inputfiles)

Run the rastertool to a set of input files.

Filtering.with_filter_configuration(argsdict)

Configure the filter with its specific arguments' values

Filtering.with_output([outputdir])

Set up the output.

Filtering.with_vrt_stored(keep_vrt)

Configure if the intermediate VRT images that are generated when handling the input files (which can be complex raster product composed of several band files) shall be stored to disk or not - for debug purpose for instance.

Filtering.with_windows([window_size, pad_mode])

Configure the window generation for processing image