// Kaleidoscope Macro completed by David Marso 12/14/2007 // ImageJ applied to computationally intensive artistic endeavors // Designed to work with square images. // david.marso@gmail.com setBatchMode(false); WindowName=getTitle(); //Set initial values for dialog// ; w=getWidth; h=getHeight; // Reasonable defaults which will not zero out before 100 iterations //; Scpct=99; Mpct=0.3; MScale=10; SCsize =500; Niter=100; //Present Dialog //; Dialog.create("Cropper"); Dialog.addNumber ("Scale Pct:", Scpct ); Dialog.addNumber ("Margin Pct:", Mpct ); Dialog.addNumber ("Margin Scaler:", MScale ); Dialog.addNumber ("Stack Size:", SCsize ); Dialog.addNumber ("Iterations:", Niter ); Dialog.addString("Name", "Kaleid"); Dialog.show(); //Extract parameters from dialog //; Scpct = Dialog.getNumber(); Mpct=Dialog.getNumber(); MScale=Dialog.getNumber(); SCsize=Dialog.getNumber(); Niter =Dialog.getNumber(); NewName=Dialog.getString(); NewName = NewName + "_" + Scpct + "_" + Mpct + "_" + MScale; zeroedAt=-1; //Do it in the background for processing efficiency//; setBatchMode(true); Scpct= Scpct/100; //Create stack of requested dimensions //; newImage(NewName, "RGB White", SCsize, SCsize, Niter); //Set scale in half for quarters of images//; SCsize= SCsize/2; //Loop for the number of requested iterations//; for (i=1; i<=Niter ; i++) { print ("iteration " + i); //Set our margin reduction size//; MPixels = round (Mpct/100* MScale *sqrt(i) *w); //Build scaled cropping of Main image//; showStatus("Iteration " + i + " of " + Niter ); showProgress(i/Niter); xsize= round(pow(Scpct,i) * w) ; xsize=xsize-MPixels; if (xsize > 0) { selectWindow(WindowName); makeRectangle(MPixels, MPixels, xsize, xsize); run("Scale...", "x=- y=- width=" + SCsize + " height=" + SCsize + " create title=SC"); // Create symmetrical montage from scaled section //; run("Select All"); run("Copy"); run("Add Slice"); run("Paste"); run("Flip Horizontally", "slice"); run("Add Slice"); run("Paste"); run("Flip Vertically", "slice"); run("Add Slice"); run("Paste"); run("Flip Horizontally", "slice"); run("Flip Vertically", "slice"); run("Make Montage...", "columns=2 rows=2 scale=1 first=1 last=4 increment=1 border=0"); //Copy the montage to the clipboard//; run("Select All"); run("Copy"); //Close the montage//; close(); //Close the scaled image//; selectWindow("SC"); close(); //Add newly created image to the stack//: selectWindow(NewName); setSlice(i); run("Paste"); selectWindow(WindowName); run("Select None"); } else { //Flip flag to trigger cleanup /; if (zeroedAt < 0) zeroedAt=i; } } selectWindow(NewName); //Clean up allocated but blank slices from stack //; if (zeroedAt > 0) { for (i= zeroedAt; i<=Niter ; i++) { setSlice(zeroedAt); run("Delete Slice"); } } setSlice(1); setBatchMode(false); run("Animation Options...", "speed=15 loop start");