Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import struct
- import time
- s = time.time()
- with open(sys.argv[1], 'rb') as f:
- data = f.read()
- r, g, b = 0, 0, 0
- r, g, b = 1, 1, 1
- w=4192
- h=3104
- pixels = struct.unpack("<%dH" % (w*h), data)
- d = time.time()
- for i in range(h):
- if i % 2 == 0:
- r += sum(pixels[i*w:(i+1)*w:2])
- g += sum(pixels[i*w+1:(i+1)*w+1:2])
- else:
- g += sum(pixels[i*w:(i+1)*w:2])
- b += sum(pixels[i*w+1:(i+1)*w+1:2])
- r=r/w/h*4
- g=g/w/h*2
- b=b/w/h*4
- m=(r+g+b)/3
- e = time.time()
- print('\rR', round(r, 2), round(m/r, 3), round(g/r, 3))
- print('G', round(g, 2), round(m/g, 3), '1.000')
- print('B', round(b, 2), round(m/b, 3), round(g/b, 3))
- print("total time: %.3f seconds. Data read/prepare: %.3f" % ((e - s), (d - s)))
Advertisement
Add Comment
Please, Sign In to add comment