In most examples I have seen that work with loadImage, you usually work with single images, but what If you want to process at least 100 images with the same script?
How would you load images from a data folder so that
For Example, when the script is done loading, I would like to save the frame and exit, but I’m wondering if I had a data folder with multiple images, how could I process each image in the data folder one after another?
Something with i++ ? Is that something that would be read within setup?
At that point - would the exit command not be needed? It would need to save after every new image is loaded rather than close.
Here is the script I have that works with a single image
int cnt;
PImage myImg;
int step = 7;//spacing between lines
float minlength = 5;
float maxlength = 15;
//setup is called once on startup
void setup(){
size(1980,1020);
background(0);
cnt = 0;
myImg = loadImage(“1.png”);
//draw the image the image to the screen
//image(myImg,0,0);
myImg.loadPixels();//allows us to access pixel array
for(int x = 0; x < myImg.width; x+=step){
for(int y = 0; y< myImg.height; y+=step){
int i = floor(x+ymyImg.width);
float br = brightness(myImg.pixels[i]);
if (br > 0){
stroke(myImg.pixels[i]);
strokeWeight(1);
float factor = (br/255)(maxlength - minlength) +minlength;
float x1 = x - factor *3.8;
float y1 = y - factor /2;
line(x,y,x1,y1);
}
}
}
myImg.updatePixels();
saveFrame();
}
//draw is called continuously on repeat
void draw(){
}
I’m wondering if something like this will work?
gens = 100
if(frameCount == gens){
saveFrame();
exit();
I’m thinking something like this? But instead of exit - load next image from data folder
This is the cause of your error … what you are looking to do is check to see if i is less than the number of elements in the array. There is no size() method in the array, but there is the built in length property to determine the size of the array.
It seems that loadPixels() cannot invoke on the array type PImage.
I also tried // the rest of the code that would use the hatch, and the images are never drawn to the screen with. Procesing is much more difficult writing than I thought!
for (int i = 0; i < myImg.length; i++) {
myImg[i] = loadImage(“DSC0” + i + “.JPG”);
}
myImg.loadPixels();//allows us to access pixel array
for(int x = 0; x < myImg.width; x+=step){
for(int y = 0; y< myImg.height; y+=step){
int i = floor(x+ymyImg.width);
float br = brightness(myImg.pixels[i]);
if (br > 0){
stroke(myImg.pixels[i]);
strokeWeight(1);
float factor = (br/255)(maxlength - minlength) +minlength;
float x1 = x - factor *3.8;
float y1 = y - factor /2;
line(x,y,x1,y1);
}
}
}
myImg.updatePixels();
saveFrame();
}
Here is some code that may help clarify your issue …
PImage[] imgs = new PImage[3];
void settings() {
size(600, 200);
for (int i = 0; i < imgs.length; i++) {
imgs[i] = loadImage("https://picsum.photos/200/200/?random?sig="+i, "png");
}
}
void setup() {
// this will throw an error
image(imgs, 0, 0);
// comment out the line above and uncomment this block then run
//for (int i = 0; i < imgs.length; i++) {
// image(imgs[i], i*200, 0);
//}
}