Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marieroald/condat_tv
Python wrapper for the fast TV denoising algorithm by Laurent Condat
https://github.com/marieroald/condat_tv
compressive-sensing denoising regularization signal-processing statistics total-variation
Last synced: 28 days ago
JSON representation
Python wrapper for the fast TV denoising algorithm by Laurent Condat
- Host: GitHub
- URL: https://github.com/marieroald/condat_tv
- Owner: MarieRoald
- License: other
- Created: 2020-12-07T07:00:40.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-05T19:18:42.000Z (almost 3 years ago)
- Last Synced: 2024-12-23T05:54:37.376Z (about 1 month ago)
- Topics: compressive-sensing, denoising, regularization, signal-processing, statistics, total-variation
- Language: C
- Homepage:
- Size: 83 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CondatTV
Cython wrapper for the efficient TV denoising algorithm by [Laurent Condat](https://lcondat.github.io/). This wrapper wraps Condats C implementation of the algorithm for use with NumPy.
The algorithm this code uses is the improved fast total variation algorithm.
The original C and MATLAB code is available on the [software page](https://lcondat.github.io/software.html) of Laurent Condat's [webpage](https://lcondat.github.io/).## Installation instructions
To install these bindings, you should have a C-compiler installed on your system. Make sure you have [NumPy](https://numpy.org/install/) and [Cython](https://cython.readthedocs.io/en/latest/src/quickstart/install.html) installed beforehand (both packages come with Anaconda by default) and write
```
pip install condat-tv
```in your terminal window. In case that does not work, you can install it directly from github by running the command
```
pip install git+https://github.com/yngvem/condat_tv.git
```## Example of denoising with total variation minimization
The following example is inspired by the experiments on syntetic data in [[1]](#[1])
```python
import condat_tv
import numpy as np
import matplotlib.pyplot as plt
```### Generate syntetic data
```python
np.random.seed(0)N = 500 # number of samples
# Generate a sparse "derivative" vector
signal_derivative = np.random.standard_normal(N)*4
for k in range(N):
signal_derivative[k] = signal_derivative[k]*(np.random.uniform(0,1)>0.95)
# Integrate the sparse derivative vector to obtain a piecewise constant vector
signal = np.cumsum(signal_derivative)# Add noise
noisy_signal = signal + np.random.standard_normal(signal.shape)
```### Plot the syntetic data
```python
plt.figure(figsize=(12, 4))plt.plot(signal, label="Signal")
plt.plot(noisy_signal, label="Noisy signal")plt.xlim(0, N)
plt.legend()
plt.title("Plot showing the signal with and without the added noies")
plt.show()
```![png](readme_images/output_5_0.png)
### Denoise and visualize the results
```python
plt.figure(figsize=(12, 4))
plt.plot(signal, label="Signal")for reg_strength in [0.5, 2, 8, 32]:
# Denoise the signal with total variation minimization
denoised_signal = condat_tv.tv_denoise(noisy_signal, reg_strength)
# Visualize denoised signal
plt.plot(denoised_signal, label=f"Reg strength: {reg_strength}")
# Calculate and print RMSE
RMSE = np.linalg.norm(denoised_signal-signal)/np.sqrt(N)
print(f"Regularisation strength: {reg_strength:.1e}, RMSE: {RMSE:.2e}")
plt.xlim(0, N)
plt.legend(ncol=5)
plt.title("Visualisation of denoising results for different regularisation strengths")
plt.show()
```Regularisation strength: 5.0e-01, RMSE: 5.70e-01
Regularisation strength: 2.0e+00, RMSE: 3.56e-01
Regularisation strength: 8.0e+00, RMSE: 5.89e-01
Regularisation strength: 3.2e+01, RMSE: 1.52e+00![png](readme_images/output_7_1.png)
# References
[1] Condat L. A direct algorithm for 1-D total variation denoising. IEEE Signal Processing Letters. 2013 Aug 15;20(11):1054-7. (link)