int numLayers = 826; // total number of layers to be processed int x = 640; // X position at which to take the YZ cross section int sourceImageHeight = 800; int sourceImageWidth = 1280; void setup() { // the width of this cross section is the Y height of each slice size(sourceImageHeight, 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 column at this X position into current image int index = (numLayers - 1 - i) * sourceImageHeight; for(int y = 0; y < sourceImageHeight; y++) pixels[index + y] = slice.pixels[y * sourceImageWidth + x]; } updatePixels(); // save the cross-section image save("cross-section.png"); }