Edge detection of images using Pillow

The python image-processing library provides an edge detection filter along with edge enhancement filters. An example is provided along with kernel.

Pillow Updated 14 May 2017 1 min read

Overview

  • Pillow - The Python Image-processing Library provides various image filters including the edge detection filters and edge enhancement filters.

  • Like the other image filter implementations provided by Pillow, edge detection filter as well is implemented using a convolution of a specific kernel onto the image.

  • The convolution matrix used by pillow for the edge detection is given by:

    (

    -1, -1, -1,

    -1, 8, -1,

    -1, -1, -1

    )

Example

python
from PIL import Image

from PIL import ImageFilter

# Create an image object

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

# Find the edges by applying the filter ImageFilter.FIND_EDGES

imageWithEdges = image.filter(ImageFilter.FIND_EDGES)

# display the original show

image.show()

# display the new image with edge detection done

imageWithEdges.show()

Output

Image before applying edge detection filter using Pillow

Image after applying edge detection filter using Pillow