Get coordinates of all black pixels, store in 2 separate arrays - one for the X, and another for the Y?
in
Programming Questions
•
1 year ago
I've tried a combination of other posts, the Learning section, and the book Processing, by Reas and Fry. Try as I might, I just can't figure out how to do this. I need Processing to load a black and white image, and store the coordinates of all black pixels in 2 arrays: 1 for their x-axis, and the other for their y-axis. How can I do this?
Here's what I have so far:
Here's what I have so far:
- PImage img;
int[] xArray;
int[] yArray;
void setup() {
size(100,100);
img = loadImage("image.jpg");
}
void draw() {
background(0);
image(img,0,0);
//Load the pixels
loadPixels();
//Loop through each pixel
for (int ix = 0; ix < pixels.length; ix++) {
for (int iy = 0; iy < pixels.length; iy++) {
//Set col to the color at that pixel
int col = color(get(ix,iy));
//If the color is less than 20 on an RGB scale (to include dark gray)
if (col < 20) {
//Add the X and Y coordinates to their respective array
append(xArray,ix);
append(yArray,iy);
}
}
}
}
1