Image analysis with ImageJ and Fiji, Part I kicks off

We’re speeding into our third module of the summer today with something completely different: image analysis! If you have hundreds of images that have to select ROIs for and dread doing it by hand, today we’ll teach you the basics of automation, including how to chug through everything in a folder and process them uniformly (and, thankfully, quickly) using macros that you can record and customize yourself. Today’s lesson is brought to you by James and Vickie from the Dustin and Schwab labs.

First off, make sure you’ve downloaded Fiji, which is basically a souped-up version of ImageJ. Also, please download a ZIP file of the images you’ll need for Vickie’s section.

For James’ section, please download the sample script and image.

Here’s a skeletonized version of James’ macro that asks for a directory where your files are, a directory where you want to save in, and it takes all image files in that directory and applies some function all of those images and changes the filename slightly in the destination directory. Here’s the file, loop_and_save.ijm.

// This will pop up two windows in succession so you can choose directories
dir1 = getDirectory(“Choose Source Directory “);
dir2 = getDirectory(“Choose Destination Directory Results “);

// This gets all the files from
list = getFileList(dir1);

// This loops through all files and opens TIFF files only
for (i = 0; i < list.length; i++) {
if(endsWith(list[i], “.tif”)) {

// Fetch the title and cut off the extension for saving
title = getTitle();
titleBase = replace(title, “.tif”, “”);

// Function that does all of the work
// This is defined below
DoStuffToImg(dir2, titleBase);

// Define the function DoStuffToImg
function DoStuffToImg(dir2, titleBase) {

// Put all of the stuff you want to do here

// Save with a slightly modified filename and close
run(“Save”, “save=[” + dir2 + titleBase + “_mod.tiff” + “]” );
run(“Close All”);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s