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.
19 lines
471 B
19 lines
471 B
5 years ago
|
from PIL import Image
|
||
|
|
||
|
|
||
|
def average_color(x, y, n, image):
|
||
|
r, g, b = 0, 0, 0
|
||
|
count = 0
|
||
|
for s in range(x, x + n + 1):
|
||
|
for t in range(y, y + n + 1):
|
||
|
pixlr, pixlg, pixlb = image[s, t]
|
||
|
r += pixlr
|
||
|
g += pixlg
|
||
|
b += pixlb
|
||
|
count += 1
|
||
|
return ((r / count), (g / count), (b / count))
|
||
|
|
||
|
img = Image.open('./lib/test-images/lot-1-car.jpg').load()
|
||
|
r, g, b = average_color(0, 0, 479, img)
|
||
|
print(r, g, b)
|