r.fill.category
Replaces the values of pixels of a given category with values of the surrounding pixels.
r.fill.category [-k] input=name output=name category=integer [nsize=integer] [maxiter=integer] [animationfile=name] [quality=integer] [--overwrite] [--verbose] [--quiet] [--qq] [--ui]
Example:
r.fill.category input=name output=name category=integer
grass.script.run_command("r.fill.category", input, output, category, nsize=19, maxiter=100, animationfile=None, quality=3, flags=None, overwrite=False, verbose=False, quiet=False, superquiet=False)
Example:
gs.run_command("r.fill.category", input="name", output="name", category=integer)
Parameters
input=name [required]
Name of input raster map
output=name [required]
Name for output raster map
category=integer [required]
Category to replace
nsize=integer
Neighborhood size in pixel
Default: 19
maxiter=integer
Maximum number of iterations
Allowed values: 1-999
Default: 100
animationfile=name
Name for animation output file
quality=integer
Quality factor for animation (1 = highest quality, lowest compression)
Allowed values: 1-5
Default: 3
-k
Keep intermediate maps
--overwrite
Allow output files to overwrite existing files
--help
Print usage summary
--verbose
Verbose module output
--quiet
Quiet module output
--qq
Very quiet module output
--ui
Force launching GUI dialog
input : str, required
Name of input raster map
Used as: input, raster, name
output : str, required
Name for output raster map
Used as: output, raster, name
category : int, required
Category to replace
nsize : int, optional
Neighborhood size in pixel
Default: 19
maxiter : int, optional
Maximum number of iterations
Allowed values: 1-999
Default: 100
animationfile : str, optional
Name for animation output file
Used as: output, file, name
quality : int, optional
Quality factor for animation (1 = highest quality, lowest compression)
Allowed values: 1-5
Default: 3
flags : str, optional
Allowed values: k
k
Keep intermediate maps
overwrite: bool, optional
Allow output files to overwrite existing files
Default: False
verbose: bool, optional
Verbose module output
Default: False
quiet: bool, optional
Quiet module output
Default: False
superquiet: bool, optional
Very quiet module output
Default: False
DESCRIPTION
r.fill.category replaces the values of pixels of a given category with values of the surrounding pixels and stores the output in a new raster map layer. The module can be used to eliminate one category from a raster map without leaving areas with NULL values, like for example when using r.reclass.area.
Areas with the given category are eroded and their pixels value is replaced with the values given by the mode of the surrounding pixels.
r.fill.category iteratively applies r.neighbors and r.mapcalc until no pixel of the category to replace is left or the maximum number of iterations is reached.
Optionally, r.fill.category can create an MPEG file animating the replacement process.
PARAMETERS
The user controls the process by setting the neighborhood size in pixels and the maximum number of iterations.
The neighborhood size (nsize) controls the size of the moving window where the mode of the values is used to assign a value to the pixels of the category to be replaced. Large values of the neighborhood size can speed the process considerably but can also lead to unwanted effects where pixels with the category to remove are mixed with pixels with different categories. Small values of neighborhood size require a large number of iterations, therefore longer processing times, but provide better results when categories are mixed.
The maximum number of iterations (maxiter) is limited to 999 because the name of the temporary map at each step uses three digits to identify the iteration.
INTERMEDIATE MAPS
To save space, maps generated at each iteration are removed as soon as they are used. It is possible to keep these maps using the k flag.
ANIMATION
If the user provides the name of an MPEG output file, an animation is created by combining the raster maps of each step.
The quality (1-5) parameter controls the quality of the MPEG, lower values will yield higher quality images, but with less compression (i.e. larger MPEG file size). Switching from quality=1 to quality=5 reduces the MPEG file size of about 40%, although the actual compression ratio depends on the number of frames.
The module r.out.mpeg is used to generate the MPEG file, therefore the program mpeg_encode (aka ppmtompeg) must be available. See r.out.mpeg manual for more information.
If a name for an MPEG output file is provided but the k flag is not set, intermediate maps are kept during the process and deleted after the MPEG file has been created.
EXAMPLE
In this example, the lakes in the landuse map in the North Carolina sample dataset location are replaced by categories of the surrounding pixels:
# set the region on the landuse map
g.region rast=landuse@PERMANENT
# replace pixels of category 6 (water) with values of the surrounding pixels
# create a drought.mpg animation file in the current directory
r.fill.category input=landuse@PERMANENT output=landuse_dry category=6 animationfile=./drought.mpg
It removes all water pixels in 38 iterations. A drought.mpg MPEG file containing the animation of the replacement sequence is created in the current directory.
SEE ALSO
r.neighbors, r.reclass.area, r.out.mpeg, r.fill.gaps
AUTHORS
Paolo Zatelli and Stefano Gobbi, DICAM, University of Trento, Italy.
SOURCE CODE
Available at: r.fill.category source code
(history)
Latest change: Thursday Feb 20 13:02:26 2025 in commit 53de819