python-backend/image_tools.py

23 lines
671 B
Python
Raw Normal View History

2019-02-09 21:33:44 +00:00
def average_color(x, y, w, h, image):
2019-02-09 09:05:07 +00:00
r, g, b = 0, 0, 0
count = 0
2019-02-09 21:33:44 +00:00
print([x, y, w, h])
for s in range(x, x + w + 1):
for t in range(y, y + h + 1):
2019-02-09 09:05:07 +00:00
pixlr, pixlg, pixlb = image[s, t]
r += pixlr
g += pixlg
b += pixlb
count += 1
return ((r / count), (g / count), (b / count))
def differences(rgb_tuple1, rgb_tuple2):
r1, g1, b1 = rgb_tuple1
r2, g2, b2 = rgb_tuple2
return ((r1-r2), (g1-g2), (b1-b2))
def threshold(diff_tuple, trigger=4):
dr, dg, db = diff_tuple
return (((( dr**4 + dg**4 + db**4 ) / 3)**0.25) > trigger) # Thanks to Thomas Atkins, math whiz