-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtotalvariation.py
More file actions
36 lines (27 loc) · 1.06 KB
/
totalvariation.py
File metadata and controls
36 lines (27 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
import matplotlib.pyplot as plt
import cv2
from skimage.restoration import (denoise_tv_chambolle, denoise_bilateral,
denoise_wavelet, estimate_sigma)
from skimage import data, img_as_float, color
from skimage.util import random_noise
noisy = cv2.imread('img1.jpg')
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(16, 10),
sharex=True, sharey=True)
plt.gray()
# Estimate the average noise standard deviation across color channels.
sigma_est = estimate_sigma(noisy, multichannel=True, average_sigmas=True)
# Due to clipping in random_noise, the estimate will be a bit smaller than the
# specified sigma.
print("Estimated Gaussian noise standard deviation = {}".format(sigma_est))
ax[0].imshow(noisy)
ax[0].axis('off')
ax[0].set_title('Noisy')
ax[1].imshow(denoise_tv_chambolle(noisy, weight=0.1, multichannel=True))
ax[1].axis('off')
ax[1].set_title('TV')
ax[2].imshow(denoise_tv_chambolle(noisy, weight=0.2, multichannel=True))
ax[2].axis('off')
ax[2].set_title('(more) TV')
fig.tight_layout()
plt.show()