Created
July 14, 2022 12:28
-
-
Save 2minchul/0d45fb547dbf298d9fd6b30866b09465 to your computer and use it in GitHub Desktop.
Get RGB average of PIL image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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