# # a q&d example of some fun things to do with images. # this will create a black/white image based on a threshhold # value, or laternatively turn a color image into a grayscale one # # comment/uncomment the relevant sections as needed. # # written by e.bonakdarian nov 2010 import Image BLACK = 0, 0, 0 WHITE = 255, 255, 255 THRESHHOLD = 110 im = Image.open('image.jpg') ar = im.load() rows = im.size[1] cols = im.size[0] for r in range(rows): for c in range(cols): pix = ar[c, r] avg = (pix[0] + pix[1] + pix[2]) / 3.0 ar[c, r] = avg, avg, avg ## if (avg > THRESHHOLD): ## ar[c, r] = BLACK ## else: ## ar[c, r] = WHITE im.show()