Metadata-Version: 2.4
Name: pycirclemedianfilter
Version: 1.0.0
Summary: Fast median filtering for circle-valued (phase / orientation) data — Python bindings for the C++ reference implementation
Author-email: Martin Storath <martin.storath@thws.de>, Andreas Weinmann <andreas.weinmann@thws.de>
License: MIT License
        
        Copyright (c) 2017 Martin Storath, Andreas Weinmann
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/mstorath/CircleMedianFilter
Project-URL: Repository, https://github.com/mstorath/CircleMedianFilter
Project-URL: Bug Tracker, https://github.com/mstorath/CircleMedianFilter/issues
Keywords: circle-median-filter,phase-data,orientation,median-filter,image-processing,signal-processing,variational-methods
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: C++
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.20
Provides-Extra: demos
Requires-Dist: matplotlib>=3.6; extra == "demos"
Requires-Dist: Pillow>=9; extra == "demos"
Provides-Extra: test
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: matplotlib>=3.6; extra == "test"
Requires-Dist: Pillow>=9; extra == "test"
Dynamic: license-file

# CircleMedianFilter (CMF) — Fast median filtering for phase or orientation data

[![PyPI](https://img.shields.io/pypi/v/pycirclemedianfilter.svg)](https://pypi.org/project/pycirclemedianfilter/)
[![Python](https://img.shields.io/pypi/pyversions/pycirclemedianfilter.svg)](https://pypi.org/project/pycirclemedianfilter/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![MATLAB](https://img.shields.io/badge/MATLAB-supported-orange.svg)](#matlab)
[![View Circle Median Filter on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://de.mathworks.com/matlabcentral/fileexchange/62509-circle-median-filter)

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.

![alt tag](https://hci.iwr.uni-heidelberg.de/sites/default/files/publications/teaserimages/1908951751/mediancircularrevision_teaser_small.png)

*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

<img src="docs/eqArcDistanceMedian.png" width="40%">

where d denotes the arc distance length of two angles, and r, t are the horizontal and vertical "radii" of the filter mask.

## Paper

> M. Storath, A. Weinmann.
> [*Fast median filtering for phase or orientation data.*](https://doi.org/10.1109/TPAMI.2017.2692779)
> IEEE Transactions on Pattern Analysis and Machine Intelligence, 40(3):639–652, 2018.
> [preprint](https://hci.iwr.uni-heidelberg.de/sites/default/files/profiles/mstorath/files/storath2017fast.pdf)

## Quickstart

### Python

```bash
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/`](demos_python/) for examples.

### MATLAB

- Run `CMF_install.m` in the MATLAB console and follow the demos in [`demos_matlab/`](demos_matlab/).

### C++

- Compile `CMF_library.cpp`. The relevant functions are `medfiltCirc2D` and `medfiltCirc2DQuant`. Their usage is documented as comments in `CMF_library.cpp`.

## Runtime comparison

Time complexity with respect to filter mask size is

- linear for non-quantised data,
- constant for quantised data.

<img src="docs/runtime.png" width="80%">

## Applications

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

   ![InSAR](docs/InSAR.png)

- Smoothing of orientation data, e.g. wind directions

   <img src="docs/windDirections.png" width="60%">

- Smoothing of vector fields in polar coordinates, e.g. optical-flow images.

## Updates

- 2025/02/18: Added Python bindings for the core C++ filtering code.

## Contents

- `demos_matlab/` — MATLAB demos
- `demos_python/` — Python demos
- `auxiliary/` — helper functions (MATLAB)
- `filters/` — the fast algorithms for median filtering of circle-valued data (C++ with MATLAB wrappers)

## How to cite

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`](CITATION.cff) and renders BibTeX/APA.

## Selected user applications

- S. Quan et al. *Derivation of the orientation parameters in built-up areas: with application to model-based decomposition.* IEEE Transactions on Geoscience and Remote Sensing, 2018.
- H. Salmane et al. *A method for the automated detection of solar radio bursts in dynamic spectra.* J. Space Weather Space Clim. 2018.
- B. Guo, J. Wen, Y. Han. *Deep material recognition in light-fields via disentanglement of spatial and angular information.* ECCV 2020.

## See also

Sibling projects from the same research program on variational methods for signal and image processing:

- [Pottslab](https://github.com/mstorath/Pottslab) — multilabel image segmentation via the Potts / piecewise-constant Mumford-Shah model
- [L1TV](https://github.com/mstorath/L1TV) — exact L1-TV regularisation of real- or circle-valued signals
- [CSSD](https://github.com/mstorath/CSSD) — cubic smoothing splines for signals with discontinuities
- [MumfordShah2D](https://github.com/mstorath/MumfordShah2D) — edge-preserving image restoration via the Mumford-Shah model
- [DCEBE](https://github.com/mstorath/DCEBE) — bolus arrival time estimation for DCE-MRI signals

## License

Released under the MIT License. See [LICENSE](LICENSE).
