| pkfilter(1) | pkfilter(1) |
pkfilter - program to filter raster images
pkfilter
-i input -o output [-f filter |
-srf file [-srf file]... | -fwhm
value [-fwhm value]... ] [options] [advanced
options]
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 separately 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).
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 (-dz 1), using a linear interpolation
pkfilter -i input.tif -o smoothed.tif -dz 1 -f smoothnodata -interp linear
Example: Filter input.tif in spatial domain with morphological dilation filter with kernel size 3x3.
pkfilter -i input.tif -o dilated.tif -dx 3 -dy 3 -f dilate
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 window |
| 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 -i input.tif -o median.tif -dx 3 -dy 3 -f median
Example: Calculate statistical variance in spectral/temporal domain (single output band)
pkfilter -i input.tif -o var.tif -dz 1 -f var
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 percentile of coefficients |
Example: Calculate discrete wavelet in spatial domain
pkfilter -i lena.tif -o lena_dwt.tif -f dwt
Example: Calculate discrete wavelet in spectral/temporal domain
pkfilter -i timeseries.tif -o dwt.tif -f dwt -dz 1
The number of output bands equals number of input bands
| Filter | Description |
| dwt_cut_from | discrete wavelet + inverse transform, setting all high frequence coefficients to zero (scale >= threshold) |
Example: Calculate low frequency time series based on discrete wavelet + inverse transform in spectral/temporal domain, retaining only coefficients until scale 3.
pkfilter -i timeseries.tif -o lowfrequency.tif -f dwt_cut_from -dz 1 -t 4
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 window |
| 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 -i lena.tif -o sobelx.tif -f solbelx -dx 5 -dy 5
Advanced options
Filtering in spatial domain
Filter input.tif with morphological dilation filter. Use a circular kernel (instead of rectangular) of size 3x3.
pkfilter -i input.tif -o filter.tif -dx 3 -dy 3 -f dilate -circ
Similar to previous example, but consider only values of 255 for filtering operation. Typical usage: dilate cloud values in input image that are flagged as 255
pkfilter -i input.tif -o filter.tif -dx 3 -dy 3 -class 255 -f dilate -circ
Filtering in spectral/temporal domain
Calculate the median value for each pixel, calculated on a moving window of width 3 (-dz 3) over all input bands. The output raster dataset will contain as many bands as the input raster dataset.
pkfilter -i input.tif -o filter_stdev.tif -dz 3 -f median
No moving window (-dz 1). Calculate the standard deviation for each pixel, calculated on all input bands. The output raster dataset will contain a single band only.
pkfilter -i input.tif -o filter_stdev.tif -dz 1 -f stdev
"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_periodic, 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 -i input.tif -o input_smoothed.tif -dz 1 -f smoothnodata -interp linear
| 01 April 2024 |