Login  Register

Re: macro help please - bad behavior

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

(resent this because I don't thing my tables were formated so they can  
be read)

My macro is to process a set of forest canopy images and calculate the %
of canopy area:

   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();
       getThreshold(lower,upper);
       run("Convert to Mask");
       run("Invert");
       run("Measure");
       setResult("LowerThresh",nResults-1,lower);
       setResult("UpperThresh",nResults-1,upper);
       updateResults();
       close();
   }

The problem is that I get the incorrect results for the inverted image
for the first and second file but not the third; if I remove the  
'run("Invert");'
statement then the first two files' results are ok  but now the third  
file
measurement is wrong (it's for an inverted image).  The files are
in the same folder.  I'm on Windows XP.  I've got 2000 files to analyze.
What am I missing?

file1 %area: 19.79 (incorrect)
file2 %area: 18.95 (incorrect)
file3 %area: 76.62

after run("Invert"); removed from macro

file1 %area 80.21
file2 %area 81.05
file3 %area 23.38 (incorrect)

With just two other files I get a similar behavior between first and  
second file.

file1 %area 22.45 (incorrect)
file2 %area 80.21

after run("Invert") removed from macro

file1 %area 77.55
file2 %area 19.79 (incorrect)