22 lines
647 B
Python
22 lines
647 B
Python
def average_color(x, y, w, h, image):
|
|
r, g, b = 0, 0, 0
|
|
count = 0
|
|
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
|