X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=research%2FTCS%2Fpressure%2Fget_data.py.old~;fp=research%2FTCS%2Fpressure%2Fget_data.py.old~;h=ab1bf36477309470e7136dabd98c5a83a24eb4c2;hb=70a96cca12cb006506461d26cd112bab179fe74c;hp=0000000000000000000000000000000000000000;hpb=8caf60af39689a3546074f0c68d14c3a2e28191e;p=matches%2Fhonours.git diff --git a/research/TCS/pressure/get_data.py.old~ b/research/TCS/pressure/get_data.py.old~ new file mode 100755 index 00000000..ab1bf364 --- /dev/null +++ b/research/TCS/pressure/get_data.py.old~ @@ -0,0 +1,77 @@ +#! /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) + +