// Running Average macro by Christophe Leterrier // 02/10/2011 // Averages an image sequence (typically a time-lapse movie) with a given number of frames (± window half-width) around each frame // Averages more to the right in first frames, more to the left in last frames, in order to keep the number of averages frames constant // This is different form the "Running Z Projector" plugin by N. Stuurman because : // • it is not a "grouped" projection, each frame is used for all averages around it // • the output is a stack with the same number of frames than the input stack. macro "Running_Average" { //Setting for the running average window half-width Half_Width=10; setBatchMode(true); // Retrieves parameters of the input stack Stack_Title=getTitle(); Stack_ID=getImageID(); Stack_Slices=nSlices; // Duplicates the input stack to generate the output stack run("Duplicate...", "title="+Stack_Title+" duplicate"); Filt_ID=getImageID(); // Loops on all stack slices for (i=1; iStack_Slices-Half_Width) { Start=Stack_Slices-2*Half_Width; Stop=Stack_Slices; } // Middle frames (symetrical ± half-width) else { Start=i-Half_Width; Stop=i+Half_Width; } // Projects from Start to Stop slices and copies the result image selectImage(Stack_ID); run("Z Project...", "start="+Start+" stop="+Stop+" projection=[Average Intensity]"); run("Select All"); run("Copy"); close(); // Paste the projected image in the output stack selectImage(Filt_ID); setSlice(i); run("Paste"); run("Select None"); } // Renames the output stack selectImage(Stack_ID); rename(Stack_Title+"_Running"); setBatchMode("exit and display"); showStatus("Running_Average finished"); }