I would like to use the badwitch effect on the images in the "date" folder and export it to the "output" folder

please format code with </> button * homework policy * asking questions

PImage foto;

int maxImages = 4; // Img in totale
int imageIndex = 0; // Img iniziale

PImage images = new PImage[maxImages]; // Serie di Img
// images = new PImage{image1, image2, image3};

void setup() {
size(500, 500);

foto=loadImage(“Data/nin1.jpg”);
badwitch(foto.pixels);

for (int i = 0; i < images.length; i ++ ) {
images[i] = loadImage( “nin” + i + “.jpg” );

}
frameRate(1);

}

void draw() {

image(images[imageIndex], 0, 0);
imageIndex = (imageIndex + 1);
saveFrame(“output/file_####.png”);

}

void badwitch(int pixels) {
for (int i=0; i<pixels.length; i++) {
int c=pixels[i];
float b=(c&0xff)/255f;
pixels[i]=color(255*badwitch(b));
}
}

float badwitch(float u) {
float invert=0.5;
float r;
if (u<invert)
r=map(u, 0, invert, 1, 0);
else
r=map(u, invert, 1, 0, 1);
return r;
}

Next time please format your code. It makes it so much easier to read and it improves chances to be answered.

Your quite close with your code and it needs a few replacement of code lines and a few new lines of code.

PImage foto;

int maxImages = 4; // Img in totale
int imageIndex = 0; // Img iniziale

PImage[] images = new PImage[maxImages]; // Serie di Img
//[] images = new PImage[]{image1, image2, image3};

void setup() {
  size(500, 500);

  foto=loadImage("Data/nin1.jpg");

  for (int i = 0; i < images.length; i ++ ) {
    images[i] = loadImage( "nin" + i + ".jpg" );
  }
  //frameRate(1); //not needed unless you really want to see each image separately for a second
}

void draw() {
  for(PImage photo: images) {
    photo.loadPixels(); //To get access to pixel array 
    badwitch(photo.pixels);
    photo.updatePixels();  //stores changes made to pixel array
    image(photo, 0, 0);
    imageIndex = (imageIndex + 1);
    saveFrame("output/file_" + imageIndex + ".png");
  }
}

void badwitch(int[] pixels) {
  for (int i=0; i<pixels.length; i++) {
    int c=pixels[i];
    float b=(c&0xff)/255f;
    pixels[i]=color(255*badwitch(b));
  }
}

float badwitch(float u) {
  float invert=0.5;
  float r;
  if (u<invert)
    r=map(u, 0, invert, 1, 0);
  else
    r=map(u, invert, 1, 0, 1);
  return r;
}

I always wonder why so many users have this on the top of their post and then continue with an unformatted code.

Thank you, but, how can I stop at function at the fourth image?

Well, it stops at last (fourth) image. If you want to end the program you can add exit() at the end of draw().

for(PImage photo: images) {

is same thing as

for(int i = 0; i < images.length, i++) {
  PImage photo = images[i];

wondered what badwitch effect is…

NIN

For code you don’t want repeated over and over again, (usually) better to put it in the setup() section. You may want to stopit with exit() or noLoop(). draw() section loops all the time.

EDIT: Partly what @SomeOne also said… (I should read pror posts better)