-
-
Save savage69kr/3dc7bcca3ea50b08cd73d5d3df250534 to your computer and use it in GitHub Desktop.
Atkinson dithering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
import sys, PIL.Image | |
img = PIL.Image.open(sys.argv[-1]).convert('L') | |
threshold = 128*[0] + 128*[255] | |
for y in range(img.size[1]): | |
for x in range(img.size[0]): | |
old = img.getpixel((x, y)) | |
new = threshold[old] | |
err = (old - new) >> 3 # divide by 8 | |
img.putpixel((x, y), new) | |
for nxy in [(x+1, y), (x+2, y), (x-1, y+1), (x, y+1), (x+1, y+1), (x, y+2)]: | |
try: | |
img.putpixel(nxy, img.getpixel(nxy) + err) | |
except IndexError: | |
pass | |
img.show(command="/usr/bin/gimp") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment