Skip to content

Instantly share code, notes, and snippets.

@2minchul
Created July 14, 2022 12:28
Show Gist options
  • Save 2minchul/0d45fb547dbf298d9fd6b30866b09465 to your computer and use it in GitHub Desktop.
Save 2minchul/0d45fb547dbf298d9fd6b30866b09465 to your computer and use it in GitHub Desktop.
Get RGB average of PIL image
from PIL import Image
def get_rgb_average(img: Image) -> tuple:
histogram = img.histogram()
r = max(range(256), key=lambda x: histogram[x])
g = max(range(256), key=lambda x: histogram[256 + x])
b = max(range(256), key=lambda x: histogram[512 + x])
return r, g, b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment