Smooth Filter In Pillow

Overview:

  • In Image-Processing, smoothing an image reduces noises present in the image and produces less pixelated image.

 

  • The smooth filters provided by Pillow are Box Filters, where each output pixel is the weighted mean of its kernel neighbours.

 

  • Pillow provides a couple of smooth filters denoted by,

  1. ImageFilter.SMOOTH
  2. ImageFilter.SMOOTH_MORE

 

  • The convolution matrix for the filter ImageFilter.SMOOTH is provided by

(

1, 1, 1,

1, 5, 1,

1, 1, 1

)

 

  • The convolution matrices for the filter ImageFilter.SMOOTH_MORE is provided by

(

1, 1, 1, 1, 1,

1, 5, 5, 5, 1,

1, 5, 44, 5, 1,

1, 5, 5, 5, 1,

1, 1, 1, 1, 1

)

 

Example:

# import the pillow modules

from PIL import Image

from PIL import ImageFilter

 

# Create an Image Object

image = Image.open("./lamp.jpg")

 

# Apply SMOOTH filters

smoothenedImage = image.filter(ImageFilter.SMOOTH)

moreSmoothenedImage = image.filter(ImageFilter.SMOOTH_MORE)

 

# Display the original image and the smoothened Images

image.show()

smoothenedImage.show()

moreSmoothenedImage.show()

 

 

Output:

Before applying smooth filter:

Before applying the smooth filter - Pillow Example

After applying smooth filter:

After applying the smooth filter - Pillow Example

After applying increased smooth filter:

After applying the smooth filter - Pillow Example


Copyright 2019 © pythontic.com