Comparing smoothing with box and Gaussian kernels using SciPy ndimage

We can apply a linear filter to smooth images using SciPy's ndimage module functions too. The following code snippet shows a demonstration of the results of applying the linear filters on the mandrill image degraded with impulse (salt-and-pepper) noise:

from scipy import misc, ndimageimport matplotlib.pylab as pylabim = misc.imread('../images/mandrill_spnoise_0.1.jpg')k = 7 # 7x7 kernelim_box = ndimage.uniform_filter(im, size=(k,k,1))s = 2 # sigma valuet = (((k - 1)/2)-0.5)/s # truncate parameter value for a kxk gaussian kernel with sigma sim_gaussian = ndimage.gaussian_filter(im, sigma=(s,s,0), truncate=t)fig = pylab.figure(figsize=(30,10))pylab.subplot(131), plot_image(im, ...

Get Hands-On Image Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.