int numLayers = 826; // total number of layers to be processed int y = 400; // Y position at which to take the XZ cross section int imageWidth = 1280; void setup() { size(imageWidth, numLayers); background (0); } void draw() { noStroke(); noSmooth(); background(0); loadPixels(); for(int i = 0; i < numLayers; i++) { //define filename as slice_XXXX.png String number = nf(i + 1, 1); String name = "slice_"; String imageType = ".png"; String filename = name + number + imageType; PImage slice; slice = loadImage("slices/" + filename); slice.loadPixels(); // copy a row at this Y position into current image int sourceIndex = y * imageWidth; int destIndex = (numLayers - 1 - i) * imageWidth; for(int x = 0; x < imageWidth; x++) pixels[destIndex + x] = slice.pixels[sourceIndex + x]; } updatePixels(); // save the cross-section image save("cross-section.png"); }