Smoothing with ImageFilter.BLUR

The following shows how the PIL ImageFilter module's filter function can be used to apply a blur to denoise a noisy image. The noise level on the input image is varied to see its impact on the blur filter. The popular mandrill (baboon) image is used as the input image for this example; the image is protected by a Creative Commons license (https://creativecommons.org/licenses/by-sa/2.0/) and can be found at https://www.flickr.com/photos/uhuru1701/2249220078 and in the SIPI image database: http://sipi.usc.edu/database/database.php?volume=misc&image=10#top:

i = 1
pylab.figure(figsize=(10,25))
for prop_noise in np.linspace(0.05,0.3,3):
im = Image.open('../images/mandrill.jpg')
# choose 5000 random locations inside image
n = int(im.width * im.height * prop_noise)
x, y = np.random.randint(0, im.width, n), np.random.randint(0, im.height, n)
for (x,y) in zip(x,y):
im.putpixel((x, y), ((0,0,0) if np.random.rand() < 0.5 else (255,255,255))) # generate salt-and-pepper noise
im.save('../images/mandrill_spnoise_' + str(prop_noise) + '.jpg')
pylab.subplot(6,2,i), plot_image(im, 'Original Image with ' +
str(int(100*prop_noise)) + '% added noise')
i += 1
im1 = im.filter(ImageFilter.BLUR)
pylab.subplot(6,2,i), plot_image(im1, 'Blurred Image')
i += 1
pylab.show()

The following screenshot shows the output. The smoothed image quality gets poorer as the input image gets noisier, as expected:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.0.25