This is one of the 100 recipes of the IPython Cookbook, the definitive guide to high-performance scientific computing and data science in Python.
import numpy as np
import matplotlib.pyplot as plt
import skimage
import skimage.filter as skif
import skimage.data as skid
import matplotlib as mpl
%matplotlib inline
def show(img):
plt.figure(figsize=(4,2));
plt.imshow(img, cmap=plt.cm.gray);
plt.axis('off')
plt.show();
img = skimage.img_as_float(skid.lena())[...,0]
show(img)
show(skif.gaussian_filter(img, 5.))
sobimg = skif.sobel(img)
show(sobimg)
from IPython.html import widgets
@widgets.interact(x=(0.01, .4, .005))
def edge(x):
show(sobimg<x)
img = skimage.img_as_float(skid.lena())
# We take a portion of the image to show the details.
img = img[200:-100, 200:-150]
# We add Gaussian noise.
img = np.clip(img + .3 * np.random.rand(*img.shape), 0, 1)
show(img)
denoise_tv_bregman
function implements total-variation denoising using split-Bregman optimization.show(skimage.restoration.denoise_tv_bregman(img, 5.))
You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).
IPython Cookbook, by Cyrille Rossant, Packt Publishing, 2014 (500 pages).