sampling image files / rgb / arrays / export
in
Programming Questions
•
2 years ago
sampling image files
hi,
I think I am sort of halfway there :
reading out all the the R - G - B values for every pixel in a series of image files. See below.
reading out all the the R - G - B values for every pixel in a series of image files. See below.
I have a few questions though:
- it's incredibly slow - any way to improve performance?
- I am writing the values in a array of type "float" - how can I save this array to a text file / and ideally put a comma in between the values for separation?
- can I convert the array to a (very long) string ?
thanks a lot for any help,
Peter
-----------------------------------------------------------------------
PImage img;
void setup() {
size(360, 240);
//img = loadImage("test.jpg");
// image(img,0,0);
}
void draw() {
float[] numbers = new float[50000000];
numbers[0]=0;
for (int i = 0; i < 1; i ++ ) {
img = loadImage( "test" + i + ".jpg" );
img.loadPixels();
image(img,0,0);
// Since we are going to access the image's pixels too
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int loc = x + y*width;
// The functions red(), green(), and blue() pull out the 3 color components from a pixel.
float r = red(img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
append(numbers,r);
//append(numbers,500)
append(numbers,g);
append(numbers,b);
println(r);
println(loc);
// Set the display pixel to the image pixel
// pixels[loc] = color(r,g,b);
}
}
//updatePixels();
/// write values to array (csv) plus at a seperator marker at the end to distinguish files
//saveStrings("numbers.dat", pixels);
append(numbers,600)
}
/// send array to udp or textfile
saveBytes("numbers.dat", numbers);
//saveStrings("nouns.txt", list);
}
1