Skip to content

Instantly share code, notes, and snippets.

@Cosmologist
Created January 31, 2014 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cosmologist/8731670 to your computer and use it in GitHub Desktop.
Save Cosmologist/8731670 to your computer and use it in GitHub Desktop.
Convert image to black and white colors - http://pickbox.ru/edit/309
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
Copy link

ghost commented Apr 10, 2018

bw = gray.point(lambda x: 0 if x < 128 else 255, '1')

what does the '1' signify at the end of the function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment