Let's see how the edge detection and enhancement filters modify the data of a picture. The photograph that we will use is a close-up of a leaf. The original photo is shown in the next illustration. Applying an edge detection filter on this image creates a cool effect where only edges are highlighted and the remaining portion of the image is rendered as black.
Download the image
0165_3_6_Before_EDGE_ENHANCE.png
from the Packt website and save it asBefore_EDGE_ENHANCE.png
.Add the following code in a Python file.
1 import Image 2 import ImageFilter 3 import os 4 paths = [ "C:\images\Before_EDGE_ENHANCE.png ", 5 "C:\images\After_EDGE_ENHANCE.png ", 6 "C:\images\EDGE_DETECTION_1.png ", 7 "C:\images\EDGE_DETECTION_2.png " 8 ] 9 paths = map(os.path.normpath, paths) 10 11 ( imgPath ,outImgPath1, 12 outImgPath2, outImgPath3) = paths 13 img = Image.open(imgPath) 14 img1 = img.filter(ImageFilter.FIND_EDGES) 15 img1.save(outImgPath1) 16 17...