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
from skimage.morphology import disk

Median filter

The median filter replaces the center pixel by taking the median of all the pixel values in the local neighbourhood. It is a non-linear filter but provides certain advantages when used for removing image noise. Note how the size of the filter is being defined.

In [3]:
image = io.imread("../images/1200px-X-ray_of_normal_hand_by_dorsoplantar_projection.jpg")
In [4]:
filtered_image = filters.median(image, disk(9))
In [5]:
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()
In [6]:
print('end of figure')
end of figure
Explore: Compare the result of the median filter with Gaussian smoothing. The median filter will preserve the position of the discontinuities or edges in the image. Try to apply very large filter to the image to observe this effect.
In [ ]: