Skip to content

Instantly share code, notes, and snippets.

@victormurcia
Created October 20, 2022 18:02
Show Gist options
  • Select an option

  • Save victormurcia/33c1202bb83d414e3f95f670bf71f5c6 to your computer and use it in GitHub Desktop.

Select an option

Save victormurcia/33c1202bb83d414e3f95f670bf71f5c6 to your computer and use it in GitHub Desktop.
determining the most common color in python, averaging
#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