// Time-Lapse Video Macros // // Based onto the Time-lapse_Capture macro, written by Wayne Rasband and available at the // http://rsb.info.nih.gov/ij/macros/Time-lapse_Capture.txt // Author: Gilles Carpentier, Faculte des Sciences et Technologie, Universite Paris 12 Val de Marne // Uses the QuickTime Capture plugin to capture a sequence. Requires a version of the plugin at // // dated 2007/05/22 or later. // Notice: // Using another macro during time-lapse capture may cause // an error unless you are running ImageJ 1.39q or later. // // This toolset proposes some functionalities around the video quicktime resources of ImageJ. // The image source is the Live ImageJ window (invisible in batch mode) and available // from the File->Import->Video menu. // It is advised to first start the live video, using the "Live Preview [l]" macro, before to use the // other macros of this macroset. // Press space bar to stop the image preview and live histogram. // Live histogram can be temporarely supended by using the "Stop Live Histogram [s]" macro menu // (use this function before handling acquired images or stacks). // Capture (as blind capture) can be aborted using the "Abort Timelapse Capturing [a]" macro menu // (the acquired stack becomesTimeLapseVideoMacros.txt visible in its states). // - Live grey levels or color histogram can be visualised by "Live Histogram macro" (shortcut h) // and "Live RGB Histogram [r]" menus. It is possible to switch from one to the other, // keeping the live histogram viewing. // - The Y scale of the histogram can be adjusted by the "Increase Live Histogram Atenuation" // and the "Decrease Live Histogram Atenuation" macro menus (respectively shorcuts "i" and "d"), // to dinamicaly optimize the live histogram visualisation. // - The interval between two calculated histograms, can be set by the // "Increase Live Histogram Interval" and the "Decrease Live Histogram Interval" macro menus // (respectively shorcuts "m" and "q"). This function can be used during live hitogram visualisation. // Some statistical infomations are given into the status area of the ImageJ toolbar (min and max level, // highest value of the histogram, and the correponding level, visualisation parameters) // - Time Lapse image acquisition can be performed with a live preview by the // "Timelapse Capture using "Live" ImageJ window" macro menu, or in batch with the // "Blind Timelapse Capture using "Live" ImageJ window" macro menu. // The live histogram viewing, if activated, will be interrupted during the image acquisitions. // Use macro menus to animate the acquired time lapse image stacks. // Change the default time lapse settings with the "Timelapse Capture Settings" macro menu. var histo=0, yHistoAtenuation=40,HistoInterval = 0.1; var TimeLapseFrames = 20, TimeLapseInterval = 0.5, abortTimeLapse=0; // seconds var delais=1000,stopHisto=0,restartHisto=0,acqui=0,RGBhistoSet=0; var greyHisto=newArray(256); var redHisto=newArray(256); var greenHisto=newArray(256); var blueHisto=newArray(256); macro "Live Preview [l]" { if (! isOpen("Live (press space bar to stop)")) doCommand("Video"); } macro "-" {} macro "Timelapse Capture using \"Live\" ImageJ window [c]" { TimeLapseConditions (); TimeLapseCapture (0,TimeLapseInterval,TimeLapseFrames); } macro "Blind Timelapse Capture using \"Live\" ImageJ window [b]" { TimeLapseConditions (); TimeLapseCapture (1,TimeLapseInterval,TimeLapseFrames); } macro "Timelapse Capture Settings [t]" { TimeLapseConditions (); Dialog.create("Timelapse Capture Settings"); Dialog.addMessage("Choose the number of frames \nand frame interval \(sec\)"); Dialog.addNumber("Nb frames", TimeLapseFrames, 0, 3, " "); Dialog.addNumber("Nb frames", TimeLapseInterval, 2, 4, "sec"); Dialog.show(); TimeLapseFrames=Dialog.getNumber(); TimeLapseInterval=Dialog.getNumber(); } macro "Abort Timelapse Capturing [a]" { if (call("ij.macro.Interpreter.isBatchMode")=="true") { beep(); if (acqui==1) abortTimeLapse=1; } } macro "-" {} macro "Animate" { if (call("ij.macro.Interpreter.isBatchMode")=="true") {beep();exit;} doCommand("Start Animation [\\]"); } macro "Animate Settings" { run("Animation Options..."); } macro "-" {} macro "Get a Single Image using \"Live\" ImageJ window [g]" { TimeLapseConditions (); if (! isOpen("Live (press space bar to stop)")) {doCommand("Video"); wait(2*delais); } acqui=1;abortTimeLapse=0; setBatchMode(true); selectWindow ("Live (press space bar to stop)"); newImage("Grab Image","RGB",getWidth,getHeight,1); grabima = getImageID; selectWindow ("Live (press space bar to stop)"); run("Copy"); selectImage(grabima); run("Paste"); run("Select None"); setBatchMode(false); acqui=0; if (histo==1 && restartHisto== 1) LiveRGBHisto (RGBhistoSet);restartHisto=0; } macro "-" {} macro "Live Grey Level Histogram [h]" { if (call("ij.macro.Interpreter.isBatchMode")=="true") { beep(); if (acqui==1) exit; RGBhistoSet=0;exit; } LiveRGBHisto (0); } macro "Live RGB Histogram [r]" { if (call("ij.macro.Interpreter.isBatchMode")=="true") { beep(); if (acqui==1) exit; RGBhistoSet=1;exit; } LiveRGBHisto (1); } macro "Stop Live Histogram [s]" { if (call("ij.macro.Interpreter.isBatchMode")=="true") { beep(); if (acqui==1) exit; stopHisto=1; wait (delais);stopHisto=0; } } macro "-" {} macro "Increase Live Histogram Atenuation [i]" { yHistoAtenuation= yHistoAtenuation+5; } macro "Decrease Live Histogram Atenuation [d]" { yHistoAtenuation= yHistoAtenuation-5; if (yHistoAtenuation < 0) yHistoAtenuation=0; } macro "Increase Live Histogram Interval [m]" { HistoInterval = HistoInterval+0.05; } macro "Decrease Live Histogram Interval [q]" { HistoInterval =HistoInterval-0.05; if (HistoInterval < 0.05) HistoInterval = 0.05; } // functions // function TimeLapseConditions () { if (call("ij.macro.Interpreter.isBatchMode")=="true") { beep(); if (acqui==1) exit; if (histo==1) stopHisto=1; restartHisto=1;wait (delais); } } // Timelapse function function TimeLapseCapture (blind,interval,frames) { setBatchMode(true); acqui=1; abortTimeLapse=0; setPasteMode("Copy"); if (blind == 0) {if (! isOpen("Live (press space bar to stop)")) {doCommand("Video"); wait(2*delais); }} // check for the video window status if (blind == 1) { if (isOpen("Live (press space bar to stop)")) { selectWindow ("Live (press space bar to stop)"); close (); wait(delais); } doCommand("Video"); wait(2*delais); } start = getTime; // acquisition for (i=1; i<=frames; i++) { showProgress(i, frames); selectWindow ("Live (press space bar to stop)"); run("Copy"); if (i==1) { newImage("Video","RGB",getWidth,getHeight,frames); stack = getImageID; } selectImage(stack); setSlice(i); run("Paste"); setMetadata(d2s((getTime-start)/1000,2)); while (getTime-starta[i]) i++; while (j>from && center