INTRO PROCESSING - Average blue pixels in an image
in
Programming Questions
•
7 months ago
Pimage img;
void setup(){
img = loadImage("wintersky.jpg");
float blueAverage (Pimage img){
//Docs say to "load pixels" before doing anything with a Pimage
img.loadPixels();
//Keep track of number of pixels
int numPixels = 0;
//Keep track of cumulative blue value
int blueSum = 0;
for (int i = 0; i < img.pixels.length; i++) {
//Increase pixel count by one
numPixels++;
//Increase blue sum by blue value of the color of the pixel at current index
blueSum = blueSum + img.pixels[i].blue();
}
//Return the sum of the blue values, divided by the number of pixels
return (float)blueSum/(float)numPixels;
}
Here's what I have so far. The question is to return the average number of blue pixels in that picture.
How do I go further? THANK YOU!
1