A common pencil-sketch effect combines a grayscale image with a blurred inversion using color-dodge blending. Pillow and NumPy make the calculation concise and avoid slow per-pixel Python loops.
Install the dependencies:
1 | python -m pip install pillow numpy |
Then save this script as sketch.py:
1 | from pathlib import Path |
Place input.jpg beside the script and run python sketch.py. Increase the blur radius for broader, softer shading; decrease it to retain finer edges. High-resolution images consume more memory, so resize a copy before processing if the source is very large.
The result depends heavily on exposure and local contrast. A small contrast adjustment after blending can help pale images, but avoid crushing all light gray detail into pure white.