GDAL-RASTER-NEIGHBORS(1) GDAL GDAL-RASTER-NEIGHBORS(1)
NAME
gdal-raster-neighbors - Compute the value of each pixel from its
neighbors (focal statistics)
Added in version 3.12.
SYNOPSIS
Usage: gdal raster neighbors [OPTIONS]
Compute the value of each pixel from its neighbors (focal statistics)
Positional arguments:
-i, --input Input raster datasets [required] [not available in pipelines]
-o, --output Output raster dataset [required] [not available in pipelines]
Common Options:
-h, --help Display help message and exit
--json-usage Display usage as JSON document and exit
--config = Configuration option [may be repeated]
-q, --quiet Quiet mode (no progress bar or warning message) [not available in pipelines]
Options:
-f, --of, --format, --output-format Output format ("GDALG" allowed) [not available in pipelines]
--co, --creation-option = Creation option [may be repeated] [not available in pipelines]
--overwrite Whether overwriting existing output dataset is allowed [not available in pipelines]
Mutually exclusive with --append
--append Append as a subdataset to existing output [not available in pipelines]
Mutually exclusive with --overwrite
-b, --band Input band (1-based index)
--method Method to combine weighed source pixels. METHOD=mean|sum|min|max|stddev|median|mode [may be repeated]
--size Neighborhood size
--kernel Convolution kernel(s) to apply [1.. values] [required]
--ot, --datatype, --output-data-type Output data type. OUTPUT-DATA-TYPE=UInt8|Int8|UInt16|Int16|UInt32|Int32|UInt64|Int64|CInt16|CInt32|Float16|Float32|Float64|CFloat32|CFloat64 (default: Float64)
--nodata Assign a specified nodata value to output bands ('none', numeric value, 'nan', 'inf', '-inf')
Advanced Options:
--if, --input-format Input formats [may be repeated] [not available in pipelines]
--oo, --open-option = Open options [may be repeated] [not available in pipelines]
DESCRIPTION
gdal raster neighbors applies a kernel (convolution matrix) and a
method to compute the target pixel value from a neighbourhood of the
source pixel value.
At the top edge, the values of the first row are replicated to
virtually extend the source window by a number of rows equal to the
radius of the kernel. And similarly for the bottom, left and right
edges. This strategy may potentially lead to unexpected results
depending on the applied kernel.
For a given target cell, if the corresponding source value (the one at
the center of the kernel) is nodata, the resulting pixel is nodata. For
other source values in the neighborhood defined by the kernel, source
nodata values are ignored.
This algorithm can be part of a gdal pipeline or gdal raster pipeline.
[image] Raster dataset before (left) and after (right) summation with
a 3x3 equal-weight kernel. NoData values are considered zero for the
purpose of the summation. Edge cells are replicated where the kernel
window extends beyond the edge of the dataset..UNINDENT
GDALG OUTPUT (ON-THE-FLY / STREAMED DATASET)
This program supports serializing the command line as a JSON file using
the GDALG output format. The resulting file can then be opened as a
raster dataset using the GDALG: GDAL Streamed Algorithm driver, and
apply the specified pipeline in a on-the-fly / streamed way.
PROGRAM-SPECIFIC OPTIONS
--band
Source band number (indexing starts at one). If it is not
specified, all input bands are used.
--kernel
Convolution kernel to apply to source pixels in a neighborhood
of each pixel.
o either the name of a well-known kernel, among edge1, edge2,
sharpen, gaussian, or unsharp-masking, corresponding to those
kernels (convolution matrix), with the addition of:
o equal corresponding to a kernel with all coefficients at one
kernel size can be any odd number between 3 and 99):
\begin{align}
\begin{bmatrix} 1 & 1 & 1\\ 1 & 1 & 1 \\ 1 & 1 & 1
\end{bmatrix} \end{align}
For method mean, this corresponds to a box blur filter.
o u corresponding to an horizontal derivative with
coefficients:
\begin{align}
\begin{bmatrix} 0 & 0 & 0\\ -0.5 & 0 & 0.5 \\ 0 & 0 & 0
\end{bmatrix} \end{align}
o v corresponding to a vertical derivative with coefficients:
\begin{align}
\begin{bmatrix} 0 & -0.5 & 0\\ 0 & 0 & 0 \\ 0 & 0.5 & 0
\end{bmatrix} \end{align}
edge1, edge2, sharpen, u and v are only supported for a
kernel size equal to 3.
gaussian is supported for a kernel size equal to 3 or 5.
unsharp-masking is supported for a kernel size equal to 5.
o or the values of the coefficients of the kernel as a square
matrix of width and height N, where N is an odd number, as
[[val00, val01, ..., val0N],[val10, val11, ...,
val1N],...,[valN0, valN1, ..., valNN]].
If --method is set to mean, this has the effect of adding the
sum of the (contributing, i.e. non nodata) weighted source
pixels and dividing it by the sum of the coefficients in the
kernel.
If --kernel is specified several times, there will one output
band for each combination of kernel and input band.
--method sum|mean|min|max|stddev|median|mode
Function to apply to the weighted source pixels in the
neighborhood defined by the kernel. Defaults to mean, except
when --kernel is set to u, v, edge1, edge2, or a user defined
kernel whose sum of coefficients is zero, in which case sum is
used.
o sum: computes the sum of the value of contributing source
pixels multiplied by the corresponding weight of the kernel.
This corresponds to a kernel with un-normalized sum of
coefficients.
o mean: computes the average of the value of contributing source
pixels multiplied by the corresponding weight of the kernel.
This has the effect of normalizing kernel coefficients so
their sum is one.
o min: computes the minimum of the value of contributing source
pixels multiplied by the corresponding weight of the kernel
o max: computes the maximum of the value of contributing source
pixels multiplied by the corresponding weight of the kernel
o stddev: computes the standard deviation of the value of
contributing source pixels multiplied by the corresponding
weight of the kernel
o median: computes the median of the value of contributing
source pixels multiplied by the corresponding weight of the
kernel
o mode (majority): computes the most frequent of the value of
contributing source pixels multiplied by the corresponding
weight of the kernel
--nodata
Set the NoData value for the output dataset. May be set to none
to leave the NoData value undefined. If --nodata is not
specified, gdal raster neighbors will use a NoData value from
the first source dataset to have one.
--size
Size of the kernel. Odd number between 3 and 99.
NOTE:
Computation time is proportional to the square of the kernel
size.
For kernels edge1, edge2, sharpen, u, v, gaussian, equal,
defaults to 3.
For kernel unsharp-masking, defaults to 5.
For kernels specified through their coefficient values, it is
deduced from the shape of the matrix.
STANDARD OPTIONS
--append
Append input raster as a new subdataset to an existing output
file. Only works with drivers that support adding subdatasets
such as GTiff -- GeoTIFF File Format and GPKG -- GeoPackage
raster This also creates the output dataset if it does not exist
yet.
--co, --creation-option =
Many formats have one or more optional creation options that can
be used to control particulars about the file created. For
instance, the GeoTIFF driver supports creation options to
control compression, and whether the file should be tiled.
May be repeated.
The creation options available vary by format driver, and some
simple formats have no creation options at all. A list of
options supported for a format can be listed with the --formats
command line option but the documentation for the format is the
definitive source of information on driver creation options.
See Raster drivers format specific documentation for legal
creation options for each format.
--if, --input-format
Format/driver name to be attempted to open the input file(s). It
is generally not necessary to specify it, but it can be used to
skip automatic driver detection, when it fails to select the
appropriate driver. This option can be repeated several times
to specify several candidate drivers. Note that it does not
force those drivers to open the dataset. In particular, some
drivers have requirements on file extensions.
May be repeated.
--oo, --open-option =
Dataset open option (format specific).
May be repeated.
-f, --of, --format, --output-format
Which output raster format to use. Allowed values may be given
by gdal --formats | grep raster | grep rw | sort
--ot, --datatype, --output-data-type
Output data type among Byte, Int8, UInt16, Int16, UInt32, Int32,
UInt64, Int64, CInt16, CInt32, Float32, Float64, CFloat32,
CFloat64.
--overwrite
Allow program to overwrite existing target file or dataset.
Otherwise, by default, gdal errors out if the target file or
dataset already exists.
RETURN STATUS CODE
The program returns status code 0 in case of success, and non-zero in
case of error (non-blocking errors emitted as warnings are considered
as a successful execution).
EXAMPLES
Example 1: Compute the horizontal and vertical derivative of a single-band
raster
gdal raster neighbors --kernel u --kernel v in.tif uv.tif
Example 2: Compute the average value around each pixel in a 3x3
neighborhood
gdal raster neighbors --kernel equal --method mean in.tif mean.tif
Example 3: Compute the maximum value around each pixel in a 5x5
neighborhood
gdal raster neighbors --kernel equal --size 5 --method max in.tif max.tif
Example 4: Compute a sharpen filter of a single-band raster, by manually
specifying the kernel coefficients.
gdal raster neighbors "--kernel=[[0,-1,0],[-1,5,-1],[0,-1,0]]" in.tif sharpen.tif
AUTHOR
Even Rouault
COPYRIGHT
1998-2026
August 18, 2026 GDAL-RASTER-NEIGHBORS(1)