Created
July 31, 2017 19:16
-
-
Save sevki/58b928dba861b5d396e7f2f1620ec64a to your computer and use it in GitHub Desktop.
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
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment