Created
May 23, 2023 12:12
-
-
Save radupotop/ea41c108de0cb987eacff6dae2a2c3ed to your computer and use it in GitHub Desktop.
Atkinson dithering
This file contains hidden or 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