Blind scoring macro for imagej?

Hi Everyone,

I’ve been trying to find a way to count birds in camera-trap data using imagej. After trying several methods of automated particle counting in imagej we have decided that a more manual approach will actually be faster and more reliable because the lighting/shadows/overlaps/etc change so much between images that the most useful data will be categorical analysis done by inspecting each image and manually categorising A, B, C, D (where A = 0 birds, B = 0-5 birds, C = 6-50 birds, D = >50 birds). I have already used the “Filename_randomizer” macro to randomize the filenames for analysis so that classification is performed blind to the order the images were taken.

I am looking for a macro or plugin that will:

  1. Open the first image in a folder when started.
  2. Waits for me to enter a category/score e.g. A, B, C, or D
  3. Immediately close that first image.
  4. Loop back to 1. and open the second image etc
  5. When all files in the folder have been viewed, I want a table/csv/xls file with two columns with the filenames in the first column and category/score in the second column.

I feel like this problem is common for manually coding large numbers of images, can anyone recommend something that works in imagej?

Thank you!


Your best bet is to script yourself a short macro… that way, it is tailored to what you need.

Use Script Parameters to obtain your folder (you will see examples of this in the links below) … such as:

#@File(label = "Input folder", style = "directory") folder

Search the Built-In Macro Functions list (linked below) to interact with the user … using functions such as:

getString(“prompt”, “default”)
Displays a dialog box and returns the string entered by the user. The first argument is the prompting message and the second is the initial string value. Exits the macro if the user clicks on “Cancel” or enters an empty string. See also: Dialog.create.

These are some helpful resources to get you started:

Hi etarena,

Thanks for the information. Unfortunately I am really struggling with this, probably because it is a totally new language to me, and also because it seems to simple that I should be able to understand it more quickly!

I cannot find an example anywhere of exactly what I want to do, but I feel it is a common problem and the code must be out there.

I am trying to write a macro but it is taking so much trial and error that it is almost more efficient to perform the entire analysis manually using preview and excel on the mac.

Can anyone help me with a short macro that does this:

  1. Open the first image in a folder of n images.
  2. Opens a dialog box which asks me for a score (A,B,C or D) for that image.
  3. Closes the first image and opens the n+1 image
  4. repeats until the nth image
  5. Produces a table of filenames and scores.

This seems very simple, but the loop tutorial does not assume a dialog box for visual scoring in every loop, and I can’t find how to place the score from each loop (from a dialog box response) in to a table. Similarly the batch processing tutorial does not help particularly because I do not want to process anything, simply to view, score, and record.

Could anyone help with an example code for a similar problem?

Thank you!


This script should do what you want:

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

num = 0;
// start processing images in folder... assumes no subfolders, only images

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(endsWith(list[i], suffix)) {
			processFile(input, output, list[i], num);
			num++; //increment num
	// save results table with scores...
	saveAs("Results", output + "/Image_Scores.csv");

function processFile(input, output, file, num) {
	// open image using Bio-Formats
	run("Bio-Formats", "open=[" + input + "/" + file +"] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
  	title = getTitle(); // get image title
  	setResult("Image", num, title);

  	// ask user for String input on grading... and set the score in the Results Table
  	score = getString("Please score this image: A, B, C, or D", "A");
  	setResult("Score", num, score);

  	// close image

And you can modify it as you need… using the links I provided above.


Hi Ellen,

Thanks so much! That works beautifully :slight_smile: Is there a way I can save it for others to use?

I will try to combine a filename randomizer or find a way to randomize the order images are presented, then it would be a very useful tool I think.

Thanks again!

1 Like

You can save the macro as a .ijm file… and share that file, having users open/run it via the Script Editor. Or you can add it to the Plugins dropdown menu… however you prefer.