A fast median filter for signals and images whose values lie on the unit circle (phase, orientation, interferometric SAR, wind directions, optical-flow angles). Linear in filter mask size for non-quantised data, constant for quantised data.

Left: A circle-valued image — every pixel takes its value on the unit circle (or in angular representation a value in (-π, π]), visualised as the hue component in the HSV colour space. Right: Effect of the circle-median filter using a 7 × 7 mask.
The (arc distance) median filter for an image y with values on the unit circle is given by

where d denotes the arc distance length of two angles, and r, t are the horizontal and vertical “radii” of the filter mask.
M. Storath, A. Weinmann. Fast median filtering for phase or orientation data. IEEE Transactions on Pattern Analysis and Machine Intelligence, 40(3):639–652, 2018. preprint
pip install pycirclemedianfilter
Input arrays are accepted in either C-order or Fortran-order (since v0.1.7 the binding auto-converts as needed). Outputs are Fortran-strided. See demos_python/ for examples.
CMF_install.m in the MATLAB console and follow the demos in demos_matlab/.CMF_library.cpp. The relevant functions are medfiltCirc2D and medfiltCirc2DQuant. Their usage is documented as comments in CMF_library.cpp.Time complexity with respect to filter mask size is

Smoothing of phase data, e.g. interferometric SAR images

Smoothing of orientation data, e.g. wind directions

Smoothing of vector fields in polar coordinates, e.g. optical-flow images.
demos_matlab/ — MATLAB demosdemos_python/ — Python demosauxiliary/ — helper functions (MATLAB)filters/ — the fast algorithms for median filtering of circle-valued data (C++ with MATLAB wrappers)If you use this software, please cite the paper above. GitHub’s “Cite this repository” button on the repo page reads the version and date-released fields from CITATION.cff and renders BibTeX/APA.
Sibling projects from the same research program on variational methods for signal and image processing:
Released under the MIT License. See LICENSE.