How To Automate ImageJ Analysis With Macros and Batch Processing
How To Automate ImageJ Analysis With Macros and Batch Processing
[email protected])
Last Updated May 29, 2012
This tutorial covers how to automate ImageJ analysis using macros and batch processing. This technique can save you a lot of time by turning what normally takes hours by hand into a 60 second process. Automation of the "threshold" tool will be used as an example, but the same technique can be applied to all commands under the "Image", "Process", or "Analyze" tabs from the ImageJ menu. ImageJ version 1.45s was used for this tutorial, and can be downloaded at http://rsbweb.nih.gov/ij/index.html .
Contents:
ImageJ Macros o o o o What is an ImageJ macro? How to create an ImageJ macro How to use an ImageJ macro How to install an ImageJ macro shortcut for repeated use
That's where an ImageJ macro comes in: it lets you record a sequence of steps (like what I described above), and then it performs the entire sequence automatically. The upcoming section covers how to create a macro, and section after that demonstrates how to run the same ImageJ macro on multiple images.
Figure 1: Click the "Macro" button to add the threshold settings to the macro sequence.
Figure 2: After clicking the "Macro" button, the sequence of steps gets added to the macro recorder window.
6. If you want to analyze the images, such as with the "Measure" or "Analyze Particles" command, select it and execute it so that the data appears in a table.
7. Once you have completed all the tasks you would like the macro to perform, find the macro Recorder window, and click "Create." A second window will pop up (shown to the right in Figure 3). Click File->Save As to save it somewhere on your computer. Make sure the file name has the extension ".ijm" at the end. This signifies it is an ImageJ Macro file.
Figure 3: The macro Recorder window is shown to the left. After clicking "Create" the macro will appear to the right. Click File->Save As to save it somewhere on your computer.
4. Click "Input..." and select the folder containing all of your images. 5. Click "Output..." and select or create a folder in which ImageJ should place all of the analyzed images. (You need to create this folder even if you don't need the images. Just delete the folder when you are done). 6. Click "Open..." towards the bottom of the Batch Process window to open a macro file located on your computer. This is the macro that will be executed on each image. 7. Once you are ready, click "Process", and watch the magic happen. ImageJ will automatically open each image from the folder you chose, apply the macro to that image, and export the analyzed data into a nice summary table (Figure 5).
Figure 5: A list of data from all the analyzed images. To set what measurements appear in the summary table, click Analyze->Set Measurements before running the batch process.