%matplotlib inline
import math
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage import filters
from skimage.morphology import disk
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.
image = io.imread("../images/1200px-X-ray_of_normal_hand_by_dorsoplantar_projection.jpg")
filtered_image = filters.median(image, disk(9))
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()
print('end of figure')