# 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
<p id="[1]">
<b>[1]</b> Condat L. A direct algorithm for 1-D total variation denoising. IEEE Signal Processing Letters. 2013 Aug 15;20(11):1054-7. <a href="https://ieeexplore.ieee.org/abstract/document/6579659">(link)</a>
<p>
PyPI 官网下载 | condat_tv-0.0.3.tar.gz
版权申诉
8 浏览量
2022-01-26
23:40:37
上传
评论
收藏 50KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- las格式点云数据使用详解(附VS编译好的LAStools工具)
- KRPano插件一键解密大师1.4.0 (解压密码1234)
- 《C++沉思录》是一本由 Scoot Meyers 所著的经典 C++ 编程书籍 该书深入探讨了 C++ 的一些高级概念和技术
- 海信刷机数据 LED42K310X3D(0000)BOM1-C006软件数据与LED42K310NX3D(0000)BOM1通用
- 送货单打印软件单机版直接单机运行不需要网络
- pycdc工具,Python3.9及以上可用的反编译工具(exe转py)
- 计算机网络基础练习题.pdf
- SDIO接口远距离无线图传WIFI6模块TT-S6D2TR-105HP
- 海信智能电视刷机数据 LED42K280J3D(1000) 生产用软件数据 务必确认机编一致 强制刷机 整机USB升级程序
- 步进电机控制实验-原理图-软件代码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈