r.mfilter(1)
π r.mfilter β Performs raster map matrix filter π
okay bestie, welcome to the GRASS GIS User's Manual, section 1, where we're talking about r.mfilter β the little module that runs your raster through a matrix filter and serves LOOKS. π
π KEYWORDS π
raster, algebra, statistics, filter, parallel
β¨ SYNOPSIS β¨
r.mfilter
r.mfilter --help
r.mfilter [-z] input=name output=name filter=name [repeat=integer]
[title=string] [nprocs=integer] [--overwrite] [--help] [--verbose]
[--quiet] [--ui]
π Flags:
-zβ Apply filter only to null data values--overwriteβ Allow output files to overwrite existing files--helpβ Print usage summary--verboseβ Verbose module output--quietβ Quiet module output--uiβ Force launching GUI dialog
π¦ Parameters:
input=name[required] β Name of input raster mapoutput=name[required] β Name for output raster mapfilter=name[required] β Path to filter filerepeat=integerβ Number of times to repeat the filter. Default:1title=stringβ Output raster map titlenprocs=integerβ Number of threads for parallel computing. Default:1
π DESCRIPTION π
So r.mfilter takes your raster input and filters it into a whole new raster output, using a matrix filter that you designed yourself (the deets are down in FILTERS, keep scrolling bestie).
Figure: Illustration for a custom 3x3 filter
The filter gets applied repeat times (default is 1, no drama). And if you want, your output raster map layer can be given a TITLE β just put that TITLE in quotes if it's more than one word, or the shell will absolutely eat it. π
With the -z flag, the filter is applied only to null values in the input raster map layer. The non-null category values are not changed, periodt. But lowkey important: if there's more than one filter step, this rule gets applied to the intermediate raster map layer β meaning only the null category values that result from the first filter will get changed. In most cases this will NOT be the desired result. So -z should only be used with single step filters, fr fr.
The filter parameter is the name of an existing, user-created UNIX ASCII file whose contents are a matrix defining the way the input file gets filtered. The format of that file is described below, under FILTERS. π
The repeat parameter is literally just the number of times the filter is applied to the input data.
π§ FILTERS π§
The filter file is a normal UNIX ASCII file that you designed. It has this format:
TITLE TITLE
MATRIX n
.
n lines of n values
.
DIVISOR d
TYPE S/P
πΈ TITLE
A one-line TITLE for the filter. If a TITLE wasn't specified on the command line, it can be specified here instead. This TITLE would be used to construct a TITLE for the resulting raster map layer. It should be a one-line description of the filter, keep it cute and concise.
π MATRIX
The matrix (n x n) follows on the next n lines. n must be an odd integer greater than or equal to 3. The matrix itself consists of n rows of n values, and the values must be separated from each other by at least 1 blank.
π DIVISOR
The filter divisor is d. If not specified, the default is 1. And if the divisor is zero (0), then the divisor is dependent on the category values in the neighborhood β see HOW THE FILTER WORKS below for the whole story.
π TYPE
The filter type. S means sequential, while P mean parallel. If not specified, the default is S.
Sequential filtering happens in place. As the filter is applied to the raster map layer, the category values that were changed in neighboring cells affect the resulting category value of the current cell being filtered.
Parallel filtering happens in such a way that the original raster map layer category values are used to produce the new category value.
More than one filter may be specified in the filter file. The additional filter(s) are described just like the first. For example, the following describes two filters:
π EXAMPLE FILTER FILE π
TITLE 3x3 average, non-null data only, followed by 5x5 average
MATRIX 3
1 1 1
1 1 1
1 1 1
DIVISOR 0
TYPE P
MATRIX 5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
DIVISOR 25
TYPE P
π₯ HOW THE FILTER WORKS π₯
The filter process produces a new category value for each cell in the input raster map layer by multiplying the category values of the cells in the n x n neighborhood around the center cell by the corresponding matrix value and adding them together. If a divisor is specified, the sum is divided by this divisor. (And if a zero divisor was specified, then the divisor is computed for each cell as the sum of the MATRIX values where the corresponding input cell is non-null β icon behavior ngl.)
If more than one filter step is specified, either because the repeat value was greater than one or because the filter file contained more than one matrix, these steps are performed sequentially. This means that first one filter is applied to the entire input raster map layer to produce an intermediate result; then the next filter is applied to the intermediate result to produce another intermediate result; and so on, until the final filter is applied. Then the output cell is written. Slay pipeline. β¨
β‘ PERFORMANCE β‘
By specifying the number of parallel processes with nprocs option, r.mfilter can run significantly faster, see benchmarks below.
Figure: Benchmark on the left shows execution time for different number of cells for 9x9 matrix, benchmark on the right shows execution time for 16 billion cells for different matrix sizes. (Intel Core i9-10940X CPU @ 3.30GHz x 28)
Note that parallelization is implemented only for the parallel filter, not the sequential one. To take advantage of the parallelization, GRASS GIS needs to compiled with OpenMP enabled.
πΈ NOTES πΈ
If the resolution of the geographic region does not agree with the resolution of the raster map layer, unintended resampling of the original data may occur. So bestie, please be sure that the geographic region is set properly. π«Ά
π SEE ALSO π
g.regionr.clumpr.neighborsr.resamp.filter- Raster Parallelization with OpenMP
π AUTHORS π
Glynn Clements. Based upon r.mfilter, by Michael Shapiro, U.S.Army Construction Engineering Research Laboratory.
Aaron Saw Min Sern (OpenMP support).
π¦ SOURCE CODE π¦
Available at: r.mfilter source code (history)
Accessed: Saturday Jan 17 05:40:50 2026
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual
and that's the whole page, no cap π
shoutout to GRASS 8.4.2 for holding it down, and shoutout to that Saturday Jan 17 05:40:50 2026 timestamp for being the moment someone actually read all this. r.mfilter(1), out. πβ¨
π¦ where this page comes from
- fedora 44: grass 8.4.2-4.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms