Introduction to ImageJ

03 - Start with macros

10 Apr 2017


Macro are made to streamline your analysis

Simply put, an ImageJ macro is a succession of existing ImageJ commands. Once you have defined exactly the type of analysis you would like to eprfom on your images, it is worth creating a macro with the different steps. This as two advantages.

First, it help you keep track of all the steps you used in your analysis. If you need to do the same analysis a year later, or ou want to check which algorithm you used when writing the paper, macro are perfect for that. They are a nice way to keep track of eveything manipulation and analysis you did on your images.

Secondly, if you need to make 1000 times the same analysis on your images, a macro is defenitivelly the way to do it. Define your pipeline on several test images. If possible pick them such as they represent the variability in your dataset. Record the step to create a macro and apply it on the whole dataset. It will save you a lot of time and avoid errors.

Record macro

> Plugins >  Macros > Record...

ImageJ macro language is a simplified version of Java

The ImageJ macro language is a modified version of Java. Therefore, they share some similarities. Some examples below.

Commented lines start with //

// This is a commented line

Each line need to finish with an ;

// Each line need to end with ";"
run("Convert to Mask");

But not foor loops start and end

// Not for loop start
for(k = 0 ;k < 10 ; k++){ 
	// But do not forget inside the loop
	print(k); 
} // Or end

The first element in a vector as the index 0

// The first element of a vector has the index 0
dir=getDirectory("Where are your images");  // ask the user to select a directory
list=getFileList(dir);	// Get the list of file in that directort as a vector of names
num=list.length;  // Get the length of the name vector

for(k = 0 ;k < num ; k++){ // Loop over the vector length
	open(dir+list[k]);   // Open each image in the vector
	close();  // Close the openned image
}

Look for existing plugins and macros

https://imagej.nih.gov/ij/plugins/





comments powered by Disqus





More ressources