Login  Register

macro help please

Posted by Larry Nolan on Dec 15, 2009; 10:28pm
URL: http://imagej.273.s1.nabble.com/macro-help-please-tp3689867.html

I'm creating a macro to process a directory of forest canopy images.  
Here's what I've got so far after wrapping a recorded macro for one  
image file:

    dir = getDirectory("Choose a Directory ");
    list = getFileList(dir);
    setOption("display labels", true);
    setBatchMode(true);

    for (i=0; i<list.length; i++) {
        path = dir+list[i];
        showProgress(i, list.length);

        open(path);

        run("8-bit");
        setAutoThreshold();
        //run("Threshold...");
        setThreshold(0, 128);
        run("Convert to Mask");
        run("Measure");

        close();
    }

My question is that I want each image to get it's own threshold set  
automatically but I'm not sure how to do that to replace the  
setThreshold(0,128) call.  What I want is to open each image, convert  
to greyscale, do an autothreshold, then convert to Binary and do the  
Measure function to calculate the percentage of black pixel which  
represent the canopy.  I think I'm close but would appreciate a review  
of what I've done so far.

  thanks,

Larry