Created
October 20, 2022 18:02
-
-
Save victormurcia/33c1202bb83d414e3f95f670bf71f5c6 to your computer and use it in GitHub Desktop.
determining the most common color in python, averaging
This file contains hidden or 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
| #Determining most frequently occurring color pixel by pixel | |
| def most_common_used_color(img): | |
| # Get width and height of Image | |
| height, width, depth = img.shape | |
| # Initialize Variable | |
| r_total = 0 | |
| g_total = 0 | |
| b_total = 0 | |
| count = 0 | |
| # Iterate through each pixel | |
| for x in range(0, height): | |
| for y in range(0, width): | |
| # r,g,b value of pixel | |
| r, g, b = (img[x, y]) | |
| r_total += r | |
| g_total += g | |
| b_total += b | |
| count += 1 | |
| return (r_total/count, g_total/count, b_total/count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment