+#! /usr/bin/python
+
+from PIL import Image
+import Image, ImageTk, ImageDraw
+import sys
+import os
+
+
+
+def PixelGood(pixel, threshold):
+ return (pixel[1] > (pixel[0] + pixel[2]) and pixel[1] > threshold)
+
+
+def rect_size(e):
+ return (e[3] - e[1]) * (e[2] - e[0])
+
+def GreyScale(pixel):
+ greyscale = 0
+ for i in range(0, len(pixel)):
+ greyscale += pixel[i]
+ greyscale = greyscale / len(pixel)
+ return greyscale
+
+def Process(threshold):
+
+ xMin = image.size[0]
+ xMax = 0
+ yMin = image.size[1]
+ yMax = 0
+
+ for x in range(0, image.size[0]):
+ for y in range(0, image.size[1]):
+ if (PixelGood(pix[x, y], threshold)):
+ if (x < xMin):
+ xMin = x
+ if (x > xMax):
+ xMax = x
+ if (y < yMin):
+ yMin = y
+ if (y > yMax):
+ yMax = y
+
+ test = Image.new("RGB", (xMax - xMin + 1, yMax - yMin + 1), "white")
+ draw = ImageDraw.Draw(test)
+
+ for x in range(xMin, xMax):
+ for y in range(yMin, yMax):
+ if (PixelGood(pix[x, y], threshold)):
+ draw.rectangle([x-xMin, y-yMin, x-xMin, y-yMin], "black")
+ else:
+ draw.rectangle([x-xMin, y-yMin, x-xMin, y-yMin], "white")
+
+ #test.show()
+ #test.resize([test.size[0]*2, test.size[1]*2]).save(output_file)
+ test.save(output_file)
+ #os.system("convert " + str(output_file) + " -resize 40% " + str(output_file))
+ sys.exit(0)
+
+
+
+if (len(sys.argv) != 3):
+ print("Usage " + str(sys.argv[0]) + " input output")
+
+input_file = sys.argv[1]
+output_file = sys.argv[2]
+
+image = Image.open(input_file)
+
+pix = image.load()
+
+# This displays all good pixels in the image; testing
+
+
+
+Process(80)
+
+