pkfilter - program to filter raster images
Contents
Description
pkfilter implements spatial and spectral filtering for raster data. In the spatial domain (X, Y), the
filter typically involves a rectangular convolution kernel (moving window). To avoid image shifting, the
size of the window should be odd (3, 5, 7, ...). You can set the window sizes in X and Y directions sep‐
arately with the options -dx and -dy. A circular kernel (disc) is applied if option -circ is set. An
overview of the supported filters (option -f|--filter) is given below. You can create customized filters
by defining your own filter taps (multiplicative elements of the filter kernel) via an ascii file (option
-tap). In the spectral/temporal domain (Z) you can filter multi-band raster inputs. The kernel filter
size can be set with the option -dz (use odd values only).
FILTERSINSPATIAL(DX,DY)ANDSPECTRAL/TEMPORAL(DZ)DOMAIN
The number of output bands equals number of input bands
Filter Description
dilate morphological dilation
erode morphological erosion
close morpholigical closing (dilate+erode)
open morpholigical opening (erode+dilate)
smoothnodata values smooth nodata values (set --nodata
option!)
Example: "Smooth" (interpolate) nodata in spectral/temporal domain (-dz1), using a linear interpolation
pkfilter-iinput.tif-osmoothed.tif-dz1-fsmoothnodata-interplinear
Example: Filter input.tif in spatial domain with morphological dilation filter with kernel size 3x3.
pkfilter-iinput.tif-odilated.tif-dx3-dy3-fdilate
In case of moving window, the number of output bands equals number of input bands. In case dz=1, the
single output band is calculated as the result of the statistical function applied to all bands.
Filter Description
nvalid report number of valid (not nodata)
values in window
median perform a median filter in spatial
(dx, dy) or spectral/temporal (dz)
domain
var calculate variance in window
min calculate minimum in window
max calculate maximum in window
sum calculate sum in window
mean calculate mean in window
stdev calculate standard deviation in win‐
dow
savgolay Savitzky-Golay filter (check examples
page!)
percentile calculate percentile value in window
proportion calculate proportion in window
Example: Median filter in spatial domain
pkfilter-iinput.tif-omedian.tif-dx3-dy3-fmedian
Example: Calculate statistical variance in spectral/temporal domain (single output band)
pkfilter-iinput.tif-ovar.tif-dz1-fvarWAVELETFILTERS
The number of output bands equals number of input bands
Filter Description
dwt discrete wavelet transform
dwti discrete inverse wavelet transform
dwt_cut discrete wavelet + inverse transform,
using threshold option to cut per‐
centile of coefficients
Example: Calculate discrete wavelet in spatial domain
pkfilter-ilena.tif-olena_dwt.tif-fdwt
Example: Calculate discrete wavelet in spectral/temporal domain
pkfilter-itimeseries.tif-odwt.tif-fdwt-dz1
The number of output bands equals number of input bands
Filter Description
dwt_cut_from discrete wavelet + inverse transform,
setting all high frequence coeffi‐
cients to zero (scale >= threshold)
Example: Calculate low frequency time series based on discrete wavelet + inverse transform in spec‐
tral/temporal domain, retaining only coefficients until scale 3.
pkfilter-itimeseries.tif-olowfrequency.tif-fdwt_cut_from-dz1-t4FILTERSINSPATIALDOMAINONLY(DX,DY>1ANDODD).
The number of output bands equals number of input bands.
Filter Description
mrf Markov random field
ismin pixel is minimum?
ismax pixel is maximum?
shift perform a pixel shift in spatial win‐
dow
scramble scramble pixels in a spatial window
mode (majority voting) perform a majority voring (set
--class option)
sobelx horizontal edge detection
sobely vertical edge detection
sobelxy diagonal edge detection (NE-SW)
sobelyx diagonal edge detection (NW-SE)
countid count digital numbers in window
order rank pixels in order
density calculated the density
homog central pixel must be identical to
all other pixels within window
heterog central pixel must be different than
all other pixels within window
sauvola Sauvola's thresholding method
Example: Sobel edge detection in horizontal direction
pkfilter-ilena.tif-osobelx.tif-fsolbelx-dx5-dy5Example
Filteringinspatialdomain
Filter input.tif with morphological dilation filter. Use a circular kernel (instead of rectangular) of
size 3x3.
pkfilter-iinput.tif-ofilter.tif-dx3-dy3-fdilate-circ
Similar to previous example, but consider only values of 255 for filtering operation. Typical usage: di‐
late cloud values in input image that are flagged as 255
pkfilter-iinput.tif-ofilter.tif-dx3-dy3-class255-fdilate-circFilteringinspectral/temporaldomain
Calculate the median value for each pixel, calculated on a moving window of width 3 (-dz3) over all in‐
put bands. The output raster dataset will contain as many bands as the input raster dataset.
pkfilter-iinput.tif-ofilter_stdev.tif-dz3-fmedian
No moving window (-dz1). Calculate the standard deviation for each pixel, calculated on all input
bands. The output raster dataset will contain a single band only.
pkfilter-iinput.tif-ofilter_stdev.tif-dz1-fstdev
"Smooth" (interpolate) nodata in spectral/temporal domain (-dz 1), using a linear interpolation. The
following interpolation types are supported: akima (default), linear, polynomial, cspline, cspline_peri‐
odic, akima_periodic (please check gsl ⟨http://www.gnu.org/software/gsl/manual/html_node/
Interpolation-Types.html⟩ page for more information on the interpolation types).
pkfilter-iinput.tif-oinput_smoothed.tif-dz1-fsmoothnodata-interplinear
01 January 2025 pkfilter(1)
Name
pkfilter - program to filter raster images
Options
-ifilename, --inputfilename
input image
-ofilename, --outputfilename
output classification image
-ffilter, --filterfilter
filter function (nvalid, median, var, min, max, sum, mean, dilate, erode, close, open, homog (cen‐
tral pixel must be identical to all other pixels within window), heterog (central pixel must be
different than all other pixels within window), sobelx (horizontal edge detection), sobely (verti‐
cal edge detection), sobelxy (diagonal edge detection NE-SW),sobelyx (diagonal edge detection NW-
SE), density, countid, mode (majority voting, only for classes), smoothnodata (smooth nodata val‐
ues only) values, ismin, ismax, order (rank pixels in order), stdev, mrf, dwt, dwti, dwt_cut,
dwt_cut_from, scramble, shift, savgolay, percentile, proportion)
-dxvalue, --dxvalue
filter kernel size in x, use odd values only
-dyvalue, --dyvalue
filter kernel size in y, use odd values only
-dzvalue, --dzvalue
filter kernel size in z (band or spectral dimension), must be odd (example: 3). Set dz>0 if 1-D
filter must be used in band domain
-nodatavalue, --nodatavalue
nodata value(s) (used for smoothnodata filter)
-vlevel, --verboselevel
verbose mode if > 0
Advanced options
-circ, --circular
circular disc kernel for dilation and erosion
-rmethod, --resampling-methodmethod
Resampling method for shifting operation (near: nearest neighbour, bilinear: bi-linear interpola‐
tion).
-cooption, --cooption
Creation option for output file. Multiple options can be specified.
-wttype, --wavelettype
wavelet type: daubechies,daubechies_centered, haar, haar_centered, bspline, bspline_centered
-wffamily, --wffamily
wavelet family (vanishing moment, see also http://www.gnu.org/software/gsl/manual/html_node/DWT-
Initialization.html)
-classvalue, --classvalue
class value(s) to use for density, erosion, dilation, openening and closing, thresholding
-tthreshold, --thresholdthreshold
threshold value(s) to use for threshold filter (one for each class), or threshold to cut for
dwt_cut (use 0 to keep all) or dwt_cut_from, or sigma for shift
-tapfilename, --tapfilename
text file containing taps used for spatial filtering (from ul to lr). Use dimX and dimY to speci‐
fy tap dimensions in x and y. Leave empty for not using taps
-tapzvalue, --tapzvalue
taps used for spectral filtering
-padmethod, --padmethod
Padding method for filtering (how to handle edge effects). Choose between: symmetric, replicate,
circular, constant (pad with 0).
-fwhmvalue, --fwhmvalue
list of full width half to apply spectral filtering (-fwhmband1-fwhmband2 ...)
-srffilename, --srffilename
list of ASCII files containing spectral response functions (two columns: wavelength response)
-wincol, --wavelengthIncol
column number of input ASCII file containing wavelengths
-woutvalue, --wavelengthOutvalue
list of wavelengths in output spectrum (-woutband1-woutband2 ...)
-downvalue, --downvalue
down sampling factor. Use value 1 for no downsampling). Use value n>1 for downsampling (aggrega‐
tion)
-betafilename, --betafilename
ASCII file with beta for each class transition in Markov Random Field
-epsvalue, --epsvalue
error marging for linear feature
-l1, --l1
obtain longest object length for linear feature
-a1, --a1
obtain angle found for longest object length for linear feature
-a2, --a2
obtain angle found for shortest object length for linear feature
-interptype, --interptype
type of interpolation for spectral filtering (see http://www.gnu.org/software/gsl/manu‐
al/html_node/Interpolation-Types.html)
-ottype, --otypetype
Data type for output image ({Byte / Int16 / UInt16 / UInt32 / Int32 / Float32 / Float64 / CInt16 /
CInt32 / CFloat32 / CFloat64}). Empty string: inherit type from input image
-ofGDALformat, --oformatGDALformat
Output image format (see also gdal_translate(1)).
-ctfilename, --ctfilename
color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)). Use none to omit
color table
Synopsis
pkfilter-iinput-ooutput [-ffilter | -srffile [-srffile]... | -fwhmvalue [-fwhmvalue]... ]
[options] [advancedoptions]
