Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created October 24, 2020 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehzawad/a1dbdc41a78e24108e89dec36c540831 to your computer and use it in GitHub Desktop.
Save ehzawad/a1dbdc41a78e24108e89dec36c540831 to your computer and use it in GitHub Desktop.
import math
import sys
from PIL import Image, ImageFilter
# ensure correct usage
if len(sys.argv) != 2:
sys.exit("Usage: Python3 edge_detection.py imagefilename")
# open image
image = Image.open(sys.argv[1]).convert("RGB")
# filtered image according to edge detection kernel
filtered = image.filter(ImageFilter.Kernel(
size=(3, 3),
kernel=[-1, -1, -1, -1, 8, -1, -1, -1, -1],
scale=1
))
# show resulting image
filtered.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment