Project-MONAI / MONAI

AI Toolkit for Healthcare Imaging
https://monai.io/
Apache License 2.0
5.87k stars 1.09k forks source link

Savitzky-Golay kernel for data smoothing #1155

Closed tvercaut closed 3 years ago

tvercaut commented 4 years ago

Is your feature request related to a problem? Please describe. Savitzky-Golay filtering is widely used in fields such as ultrasound imaging and spectral imaging. It is often a prefered option in comparison to Gaussian filtering in such applications.

Describe the solution you'd like The Savitzky-Golay filter is a simple discrete convolution filter and should thus be straightforward to integrate in a PyTorch environment such as MONAI. The computation of the kernel wigths only depends on the order of the polynomial and the window size chosen for the underpinning (implicit) least-squares fit.

Describe alternatives you've considered Exisiting options include computing the filter weights using an external routine, e.g. scipy.signal.savgol_coeffs, and then pass these weigths to PyTorch/MONAI.

Additional context A solution bypassing the dependency on scipy would be nice. The kernel computation only involves fairly basic linear algebra, all available in PyTorch.

tvercaut commented 4 years ago

A very basic notebook code to plot an exemplar kernel (using scipy):

%matplotlib inline
%config InlineBackend.figure_format = 'svg'
import timeit
import numpy as np
import scipy.signal
import matplotlib.pyplot as plt

win_radius = 5
win_length = 2*win_radius+1
xidx = range(-win_radius,win_radius+1)
order = 3
kernel = scipy.signal.savgol_coeffs(win_length,order)

plt.plot(xidx,kernel)
tvercaut commented 4 years ago

@crnbaker should be able to look into this