Last active
September 25, 2019 23:02
-
-
Save jancassio/f0d84a69f31b654b10b717d8922b3034 to your computer and use it in GitHub Desktop.
Get average color of an image
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
color averageColor(PImage image) { | |
float r = 0; | |
float g = 0; | |
float b = 0; | |
int count = image.pixels.length; | |
int[] pixels = image.pixels; | |
for(int i = 0; i < count; i++) { | |
r += red(pixels[i]); | |
g += green(pixels[i]); | |
b += blue(pixels[i]); | |
} | |
r = floor(r / (count / 4)); | |
g = floor(g / (count / 4)); | |
b = floor(b / (count / 4)); | |
return color(r, g, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment