Created
January 31, 2014 12:57
-
-
Save Cosmologist/8731670 to your computer and use it in GitHub Desktop.
Convert image to black and white colors - http://pickbox.ru/edit/309
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
def blackwhitescale(im): | |
""" | |
Convert image to black and white colors | |
Each pixel to be either fully black (0, 0, 0) or fully white (255, 255, 255) | |
""" | |
# Convert to grayscale | |
gray = im.convert('L') | |
# Scale to white or black (whichever is closest). | |
bw = gray.point(lambda x: 0 if x < 128 else 255, '1') | |
return bw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bw = gray.point(lambda x: 0 if x < 128 else 255, '1')
what does the '1' signify at the end of the function?