#!/usr/bin/env python3 from PIL import Image thresh = 10 img = Image.open('nur_oben_Dokument_gross3.png') counts = dict(map(reversed, img.getcolors(2**24))) for y in range(img.height): for x in range(img.width): cval = 0 if counts[img.getpixel((x, y))] > thresh else 255 img.putpixel((x, y), (cval, cval, cval)) img.save('nur_oben_Dokument_gross3a.png')