Re: macro help please
Posted by Larry Nolan on Dec 29, 2009; 8:59pm
URL: http://imagej.273.s1.nabble.com/macro-help-please-tp3689867p3689873.html
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?
Label
Area
Mean
Min
Max
%Area
LowerThresh
UpperThresh
CC2009P193S1C.jpg
3145728
50.46
0
255
19.79
0
133
CC2009P193S2C.jpg
3145728
48.32
0
255
18.95
0
124
CC2009P193S3C.jpg
3145728
195.38
0
255
76.62
0
91
CC2009P193S1C.jpg
2523228
255
255
255
80.21
0
133
CC2009P193S2C.jpg
2549663
255
255
255
81.05
0
124
CC2009P193S3C.jpg
735464
255
255
255
23.38
0
91
With just two files I get a similar behavior between first and second
file.
Label %Area LowerThresh
UpperThresh
C3P1931C.jpg 22.45 119 255
(incorrect %Area)
CC2009P193S1C.jpg 80.21 0 133
(correct %Area)
C3P1931C.jpg 77.55 119 255
with 'run("Invert");' removed (correct %Area)
CC2009P193S1C.jpg 19.79 0 133 with
'run("Invert");' removed (incorrect %Area)