pkfilter(1)
π NAME π
Okay bestie, meet pkfilter β it's literally the program to filter raster images. π
β¨ SYNOPSIS β¨
Here's the vibe check on how you call it:
pkfilter -i input -o output [-f filter | -srf file [-srf file]... |
-fwhm value [-fwhm value]... ] [options] [advanced options]
πΈ DESCRIPTION πΈ
Okay so bestie, 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).
β¨ FILTERS IN SPATIAL (DX, DY) AND SPECTRAL/TEMPORAL (DZ) DOMAIN β¨
The number of output bands equals number of input bands. slay β¨
dilateβ morphological dilationerodeβ morphological erosioncloseβ morpholigical closing (dilate+erode)openβ morpholigical opening (erode+dilate)smoothnodataβ smooth nodata values (set--nodataoption!) π«Ά
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.
nvalidβ report number of valid (not nodata) values in windowmedianβ perform a median filter in spatial (dx,dy) or spectral/temporal (dz) domainvarβ calculate variance in windowminβ calculate minimum in windowmaxβ calculate maximum in windowsumβ calculate sum in windowmeanβ calculate mean in windowstdevβ calculate standard deviation in windowsavgolayβ Savitzky-Golay filter (check examples page!) πpercentileβ calculate percentile value in windowproportionβ 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
π¦ WAVELET FILTERS π¦
The number of output bands equals number of input bands. iconic π
dwtβ discrete wavelet transformdwtiβ discrete inverse wavelet transformdwt_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. periodt β¨
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
π FILTERS IN SPATIAL DOMAIN ONLY (DX, DY > 1 AND ODD). π
The number of output bands equals number of input bands. ate π
mrfβ Markov random fieldisminβ pixel is minimum?ismaxβ pixel is maximum?shiftβ perform a pixel shift in spatial windowscrambleβ scramble pixels in a spatial windowmode(majority voting) β perform a majority voring (set--classoption)sobelxβ horizontal edge detectionsobelyβ vertical edge detectionsobelxyβ diagonal edge detection (NE-SW)sobelyxβ diagonal edge detection (NW-SE)countidβ count digital numbers in windoworderβ rank pixels in orderdensityβ calculated the densityhomogβ central pixel must be identical to all other pixels within windowheterogβ central pixel must be different than all other pixels within windowsauvolaβ Sauvola's thresholding method
Example: Sobel edge detection in horizontal direction
pkfilter -i lena.tif -o sobelx.tif -f solbelx -dx 5 -dy 5
π OPTIONS π
-i filename,--input filenameβ input image-o filename,--output filenameβ output classification image-f filter,--filter filterβ filter function (nvalid, median, var, min, max, sum, mean, dilate, erode, close, open, homog (central 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 (vertical 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 values only) values, ismin, ismax, order (rank pixels in order), stdev, mrf, dwt, dwti, dwt_cut, dwt_cut_from, scramble, shift, savgolay, percentile, proportion)-dx value,--dx valueβ filter kernel size in x, use odd values only-dy value,--dy valueβ filter kernel size in y, use odd values only-dz value,--dz valueβ filter kernel size in z (band or spectral dimension), must be odd (example: 3). Setdz>0if 1-D filter must be used in band domain-nodata value,--nodata valueβ nodata value(s) (used forsmoothnodatafilter)-v level,--verbose levelβ verbose mode if > 0
π Advanced options π
-circ,--circularβ circular disc kernel for dilation and erosion-r method,--resampling-method methodβ Resampling method for shifting operation (near: nearest neighbour, bilinear: bi-linear interpolation).-co option,--co optionβ Creation option for output file. Multiple options can be specified.-wt type,--wavelet typeβ wavelet type: daubechies,daubechies_centered, haar, haar_centered, bspline, bspline_centered-wf family,--wf familyβ wavelet family (vanishing moment, see alsohttp://www.gnu.org/software/gsl/manual/html_node/DWT-Initialization.html)-class value,--class valueβ class value(s) to use for density, erosion, dilation, openening and closing, thresholding-t threshold,--threshold thresholdβ threshold value(s) to use for threshold filter (one for each class), or threshold to cut fordwt_cut(use 0 to keep all) ordwt_cut_from, or sigma for shift-tap filename,--tap filenameβ text file containing taps used for spatial filtering (from ul to lr). UsedimXanddimYto specify tap dimensions in x and y. Leave empty for not using taps-tapz value,--tapz valueβ taps used for spectral filtering-pad method,--pad methodβ Padding method for filtering (how to handle edge effects). Choose between: symmetric, replicate, circular, constant (pad with 0).-fwhm value,--fwhm valueβ list of full width half to apply spectral filtering (-fwhm band1 -fwhm band2 ...)-srf filename,--srf filenameβ list of ASCII files containing spectral response functions (two columns: wavelength response)-win col,--wavelengthIn colβ column number of input ASCII file containing wavelengths-wout value,--wavelengthOut valueβ list of wavelengths in output spectrum (-wout band1 -wout band2 ...)-down value,--down valueβ down sampling factor. Use value 1 for no downsampling). Use valuen>1for downsampling (aggregation)-beta filename,--beta filenameβ ASCII file with beta for each class transition in Markov Random Field-eps value,--eps valueβ 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-interp type,--interp typeβ type of interpolation for spectral filtering (seehttp://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html)-ot type,--otype typeβ Data type for output image ({Byte / Int16 / UInt16 / UInt32 / Int32 / Float32 / Float64 / CInt16 / CInt32 / CFloat32 / CFloat64}). Empty string: inherit type from input image-of GDALformat,--oformat GDALformatβ Output image format (see alsogdal_translate(1)).-ct filename,--ct filenameβ color table (file with 5 columns: id R G B ALFA (0: transparent, 255: solid)). Usenoneto omit color table
β¨ EXAMPLE β¨
πΈ Filtering in spatial domain πΈ
Okay bestie, so say you wanna filter input.tif with a morphological dilation filter. But plot twist β you want a circular kernel instead of a rectangular one, and you want it to be size 3x3. Iconic.
pkfilter -i input.tif -o filter.tif -dx 3 -dy 3 -f dilate -circ
Same vibe as before, except this time we're only looking at values of 255 for the filtering operation. Typical usage: dilate cloud values in an input image that are flagged as 255. Very demure, very cloud-aware. βοΈ
pkfilter -i input.tif -o filter.tif -dx 3 -dy 3 -class 255 -f dilate -circ
π¦ Filtering in spectral/temporal domain π¦
Now we're in a whole different dimension (literally). Calculate the median value for each pixel, calculated on a moving window of width 3 (-dz 3) over all input bands. Heads up: the output raster dataset will contain as many bands as the input raster dataset. No shrinking, no surprises. π
pkfilter -i input.tif -o filter_stdev.tif -dz 3 -f median
No moving window (-dz 1)? Fine. Calculate the standard deviation for each pixel, calculated on all input bands. And because there's no window, the output raster dataset will contain a single band only. One band. That's it. Periodt.
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. Here are the interpolation types that are supported, bestie β take notes π:
akima(this one's the default, no cap)linearpolynomialcsplinecspline_periodicakima_periodic
Please check the gsl page http://www.gnu.org/software/gsl/manual/html_node/Interpolation-Types.html for more information on the interpolation types. π§
pkfilter -i input.tif -o input_smoothed.tif -dz 1 -f smoothnodata -interp linear
π«Ά And that's a wrap onpkfilter(1), babes! This page is from 01 January 2025, and yeah βpkfilter(1)really said "new year, same filter." Go filter something gorgeous, you absolute icon. ππ
π¦ where this page comes from
- ubuntu questing: pktools 2.6.7.6+ds-6build4
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms