https://github.com/espdev/sgolay2
Two-dimensional Savitzky-Golay filter
https://github.com/espdev/sgolay2
savgol savitzky-golay sgolay
Last synced: 4 months ago
JSON representation
Two-dimensional Savitzky-Golay filter
- Host: GitHub
- URL: https://github.com/espdev/sgolay2
- Owner: espdev
- License: mit
- Created: 2019-03-10T21:58:20.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T06:21:47.000Z (almost 5 years ago)
- Last Synced: 2025-10-11T09:12:42.963Z (4 months ago)
- Topics: savgol, savitzky-golay, sgolay
- Language: Python
- Size: 9.77 KB
- Stars: 31
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Two-dimensional Savitzky-Golay filter
A Savitzky–Golay filter is a digital filter that can be applied to a set of digital data points for the purpose of smoothing the data, that is, to increase the precision of the data without distorting the signal tendency. ([wikipedia](https://en.wikipedia.org/wiki/Savitzky–Golay_filter))
This code implements two-dimensional Savitzky-Golay filter that can be used for smoothing surfaces or images [1, 2].
## The example of usage
```python
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import sgolay2
np.random.seed(12345)
x, y = np.mgrid[-5:6:.5, -5:6:.5]
z = y * np.sin(x) + x * np.cos(y)
zn = z + np.random.randn(*x.shape) * 2.
zs = sgolay2.SGolayFilter2(window_size=9, poly_order=3)(zn)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(x, y, zn, linewidths=0.5, color='r')
ax.scatter(x, y, zn, s=5, c='r')
ax.plot_surface(x, y, zs, linewidth=0)
ax.plot_surface(x, y, z, color='y', linewidth=0, alpha=0.4)
plt.show()
```

## References
1. Ratzlaff, Kenneth L.; Johnson, Jean T. (1989). "Computation of two-dimensional polynomial least-squares convolution smoothing integers". Anal. Chem. 61 (11): 1303–5. doi:10.1021/ac00186a026.
2. Krumm, John. "Savitzky–Golay filters for 2D Images". Microsoft Research, Redmond.