We prefer to use the Fiji version of ImageJ. This version is a distribution that comes pre-packaged with the most popular ImageJ plugins. It also has a useful automatic update feature so that you are always using the most up-to-date versions of these plugins. Additional plugins can be installed as in vanilla ImageJ and also through the use of update sites.

Fiji also supports scripting using multiple programming languages (Java, Python, Ruby, Javascript) and ImageJ’s macro language. The following is an example of how to write an ImageJ macro, which shows how to make a “widefield” image from raw data captured on an NSIM microscope.It illustrates a number of features of the macro language including dealing with stacks and hyperstacks, dealing with strings, looping, using ROIs and saving files.


getDimensions(w, h, channels, slices, frames);
Stack.getPosition(channel, slice, frame);
print("   Chanels: "+channels);
print("   Slices: "+slices);
print("   Frames: "+frames);

// get total number of planes
imageCount = channels*slices*frames;
print(imageCount);

// do the rest without the images visisble - batch mode
setBatchMode(true);

// get image title
raw = getTitle();
rawid = getImageID();
print(raw);
// extract name and file extension for renaming later
name = substring(raw,0,lengthOf(raw)-4);
ext = substring(raw,lengthOf(name),lengthOf(raw));
print(name);
print(ext);

phase_dir = "C:\\Users\\Daniel\\Desktop\\phase_temp\\";
projection_dir = "C:\\Users\\Daniel\\Desktop\\proj_temp\\";

// start of looping
index = 0;
for (c = 1; c <= channels; c++) {
  for (z = 1; z <= slices; z++) {
    for (t = 1; t <= frames; t++) {
      print("processing image: ",index);
      // initialise x
      x = -512;

      // if we have multidimensional data we need to select the plane
      if (imageCount > 1) {
        selectImage(rawid);
        print("c,z,t: ",c,z,t);
        Stack.setPosition(c,z,t);
      }
            
      // loop over columns - phases
      p = 0;
      for (i = 0; i < 5; i++) {
        x = x + 512;
        y = -512;
        // loop over rows - rotations
        for (j = 0; j < 3; j++) {
          y = y + 512;
          //print(x,y);
          // grab the main window
          selectWindow(raw);
          // make a rectangle ROI
          makeRectangle(x, y, 512, 512);
          // duplicate the region
          run("Duplicate...", " ");
          run("32-bit");
          rename("image-"+p);
          saveAs("tif", phase_dir+getTitle());
          close();
          p += 1;
        }
      }

      run("Image Sequence...", "open=["+phase_dir+"image-0.tif] use");
      // sum all the slices
      run("Z Project...", "projection=[Sum Slices]");
      // save the projection
      czt = toString(c)+toString(z)+toString(t);
      print("c,z,t: ",c,z,t);
      saveAs("tif", projection_dir+czt+"_projection");
      close();
      selectWindow("phase_temp");
      close();
                
      index += 1;
    }
  }
}

// select the main window again
selectWindow(raw);
// close it
close();

// if we have multi-dimensional data concantentate it
if (imageCount > 1) {

  run("Image Sequence...", "open=["+projection_dir+"000_projection.tif]");
    
  // set the correct dimensions
  Stack.setDimensions(channels, slices, frames);
}
else {
  open(projection_dir+"000_projection.tif");
}

rename(name+"_widefield");
setBatchMode(false);