Denoising using $L_1$-norm is often used. The model is simple. We have an image $x$ and it is corrupted by noise:
$$
y = x + \eta.
$$
We want to do noise removal. The number of unknowns is larger then the number of equations, thus we have to impose a structure on the solution. And it is a piecewise-smooth structue, which implies that the gradient $\nabla x$ is sparse!
The total variation
$$
TV(x) = \Vert \nabla \Vert_1
$$
is minimized. We use scikits.image
module, which can be installed in Anaconda just as
conda install scikits-image
The example is adapted from here
In [2]:
%matplotlib inline
import numpy as np
import scipy
from scipy import ndimage
import matplotlib.pyplot as plt
from skimage import data, img_as_float
from skimage.restoration import denoise_tv_chambolle, denoise_bilateral
Load the data and add noise, plot the noisy data.
In [8]:
lena = img_as_float(data.lena())
lena = lena[220:300, 220:320]
noisy = lena + 0.6 * lena.std() * np.random.random(lena.shape)
noisy = np.clip(noisy, 0, 1)
plt.gray()
plt.imshow(noisy)
Out[8]:
And apply magic to recover!
In [5]:
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(8, 5))
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')
fig.subplots_adjust(wspace=0.02, hspace=0.2,
top=0.9, bottom=0.05, left=0, right=1)
We can also plot "the gradient", also called Sobel filter
In [16]:
from skimage import filter
img_edges = filter.sobel(lena[:, :, 2])
plt.imshow(img_edges)
Out[16]:
In [9]:
from IPython.core.display import HTML
def css_styling():
styles = open("./styles/custom.css", "r").read()
return HTML(styles)
css_styling()
Out[9]: