// This plugin converts images to binary via thresholding
// then fills any holes before counting particles and
// printing output to excel format

//Convert this to a txt file and place it in the ImageJ\plugins\Macros folder

macro "Batch Convert and Analyze" {

requires("1.33s");

setBatchMode(true);

dir = getDirectory("Choose a Directory ");

GetFiles(dir);

function GetFiles(dir){

list = getFileList(dir);

for (i=0; i<list.length; i++) {

if (endsWith(list[i], "/")) { 

              GetFiles(""+dir+list[i]); 

          } else { 

             if (endsWith(list[i], ".jpg")) { 

path = dir+list[i];

open(path);

run("Sharpen");

run("Subtract Background...", "rolling=20 light sliding");

run("Enhance Contrast", "Saturated=0.4");

run("8-bit");

setAutoThreshold("Huang");

run("Apply LUT");

run("Fill Holes");

run("Watershed");

run("Analyze Particles...", "size=100-infinity circularity=0.00-1.00 show=Outlines display include summarize record");

dotIndex = lastIndexOf(path, ".");

if (dotIndex!=-1)

path = substring(path, 0, dotIndex); // remove extension

close();

    }

  }

}

selectWindow("Summary");

saveAs("Text", dir+ "summary.xls");

selectWindow("Results");

saveAs("Text", dir+ "results.xls");

}