You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
python-backend/image_tools.py

23 lines
671 B

def average_color(x, y, w, h, image):
r, g, b = 0, 0, 0
count = 0
print([x, y, w, h])
for s in range(x, x + w + 1):
for t in range(y, y + h + 1):
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