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)