Visit the wiki pages to find some additional documentation and instructions on how view an interactive verson of these notebooks using binder.

In [1]:
%matplotlib inline
In [2]:
import math
import numpy as np
import matplotlib.pyplot as plt


from skimage import io
from skimage import filters

Apply a Gaussian smoothing filter to an image

Generate a Gaussian kernel

In [3]:
A = np.zeros((3, 3))
A[1, 1] = 1
kernel = filters.gaussian(A, sigma=0.4)
kernel
Out[3]:
array([[0.00163116, 0.03712502, 0.00163116],
       [0.03712502, 0.84496158, 0.03712502],
       [0.00163116, 0.03712502, 0.00163116]])
Explore: Try to generate a filter for a much larger value of sigma. Adjust the size of the kernel accordingly. Explore what happens when the filter is applied to pixels at the boundary of the image.
In [4]:
image = io.imread("../images/1200px-X-ray_of_normal_hand_by_dorsoplantar_projection.jpg")
In [5]:
filtered_image = filters.gaussian(image, sigma=3)
In [6]:
fig, ax = plt.subplots(figsize=(15, 15))
plt.subplot(1, 2, 1)
plt.imshow(image, cmap='gray')
plt.subplot(1, 2, 2)
plt.imshow(filtered_image, cmap='gray')
plt.show()
Explore: Compare the two images and observe how the Gaussian smoothing removes some of the noise in the image.
In [ ]:
 
In [ ]: