Access image pixels
in
Programming Questions
•
1 year ago
Hello i'm new to processing and i've no programming background.
I'm using processing to make things related to design.
So here is my question:
1. I want to analyse images accessing each pixel;
2. Store de RBG value of each pixel;
3. Calculate the average of each color value;
4. Fill the screen with the average color;
5. In the future i want the 2nd and 3rd most used colors too, but now i'm happy with one color;
I'm very basic with this language.
I've started with the code above and i want to develop it gradually if anyone can help.
Thanks
-----------------------
PImage img;
color [] imageColors;
void setup() {
size(533, 750);
background(0);
smooth();
img = loadImage( "almanaque.jpg");
}
void draw() {
loadPixels ();
img.loadPixels ();
// search each line and row of the image
for (int x=0; x < img.width; x++) {
for (int y=0; y < img.height; y++) {
int loc = x + y*img.width;
float r = red (img.pixels [loc]);
float g = green (img.pixels [loc]);
float b = blue (img.pixels [loc]);
}
}
}
1