Smooth Filter in Pillow

The smooth filters provided by the python image processing library pillow are box filters with different kernels

Pillow Updated 13 May 2017 1 min read

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

python
# 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