4 import Image, ImageTk, ImageDraw
10 def PixelGood(pixel, threshold):
11 return pixel[1] > threshold
12 return (pixel[1] > (pixel[0] + pixel[2]) and pixel[1] > threshold)
16 return (e[3] - e[1]) * (e[2] - e[0])
20 for i in range(0, len(pixel)):
22 greyscale = greyscale / len(pixel)
25 def Process(threshold):
32 for x in range(0, image.size[0]):
33 for y in range(0, image.size[1]):
34 if (PixelGood(pix[x, y], threshold)):
44 test = Image.new("RGB", (xMax - xMin + 1, yMax - yMin + 1), "white")
45 draw = ImageDraw.Draw(test)
47 for x in range(xMin, xMax+1):
48 for y in range(yMin, yMax+1):
49 if (PixelGood(pix[x, y], threshold)):
50 draw.rectangle([x-xMin, y-yMin, x-xMin, y-yMin], "black")
52 draw.rectangle([x-xMin, y-yMin, x-xMin, y-yMin], "white")
55 #test.resize([test.size[0]*2, test.size[1]*2]).save(output_file)
56 test.save(output_file)
57 #os.system("convert " + str(output_file) + " -resize 40% " + str(output_file))
62 if (len(sys.argv) != 3):
63 print("Usage " + str(sys.argv[0]) + " input output")
65 input_file = sys.argv[1]
66 output_file = sys.argv[2]
68 image = Image.open(input_file)
72 # This displays all good pixels in the image; testing
74 draw = ImageDraw.Draw(image)
75 for x in range(0, image.size[0]):
76 for y in range(0, image.size[1]):
77 #print(str(pix[x, y]))
78 if (PixelGood(pix[x, y], 220)):
79 draw.rectangle((x,y, x,y), "black")
81 draw.rectangle((x,y, x,y), "white")