comparison transformations/add_background_image.py @ 9:64dac4aabc04

Added in background script : character pixel inversion (from black to white, for dark backgrounds)
author Guillaume Sicard <guitch21@gmail.com>
date Tue, 26 Jan 2010 19:40:30 -0500
parents bdaa5bd26dcf
children 4d4248f7e2fb
comparison
equal deleted inserted replaced
8:bdaa5bd26dcf 9:64dac4aabc04
18 if len(sys.argv) < 2: 18 if len(sys.argv) < 2:
19 print "No argument, exiting" 19 print "No argument, exiting"
20 sys.exit() 20 sys.exit()
21 21
22 char_image = sys.argv[1] 22 char_image = sys.argv[1]
23 image_dir = "./images/" 23 image_dir = "./images/"
24 pattern = "*.jpg" 24 pattern = "*.jpg"
25 invert = False
25 threshold = 100; 26 threshold = 100;
26 27
27 ########### 28 ###########
28 # functions 29 # functions
29 ########### 30 ###########
53 54
54 for x in range(1, 32): 55 for x in range(1, 32):
55 for y in range(1, 32): 56 for y in range(1, 32):
56 if pix[x, y] > threshold: 57 if pix[x, y] > threshold:
57 pix[x, y] = bg_pix[x, y] 58 pix[x, y] = bg_pix[x, y]
59 elif invert:
60 pix[x, y] = 255 - pix[x, y]
58 61
59 return image 62 return image
60 63
61 ###### 64 ######
62 # main 65 # main
73 76
74 image.save(char_image + "-bg.jpg") 77 image.save(char_image + "-bg.jpg")
75 #image.show() 78 #image.show()
76 79
77 sys.stdout.write(" Done.\n") 80 sys.stdout.write(" Done.\n")
78
79