There are two problems with the following macro that batch processes a
folder of 8 bit 2560x1920 grayscale .tifs and produces binary
thresholded output:
// run("Tiff...", "save=["+path+"]") requires V 1.33t, 13 December 2004
macro 'Image Enhancement [4]' {
dir = getDirectory("Choose a Directory ");
list = getFileList(dir);
start = getTime();
setBatchMode(true);
thd=getNumber("You should already know the appropriate threshold. ENTER
IT NOW", 112);
for (i=0; i<list.length; i++) {
path = dir+list[i];
open(path);
title = getTitle();
run("Enhance Contrast", "saturated=2 normalize");
run("Median...", "radius=2"); // median filter replaces pixel
with
median of neighbors - removes noise
run("Sharpen");
run("Median...", "radius=2");
run("Subtract...", "value=1"); // so white (255) is thresholded
setThreshold(thd, 255);
run("Apply LUT");
run("Fill Holes");
run("Watershed");
run("Tiff...", "save=["+path+"]");
num= i+1;
tot= list.length;
print ("image= "+title+"... "+num+" of "+tot+"_bin");
//selectImage(title); NEEDED WITH SETBATCHMODE?
//run("Close"); ; NEEDED WITH SETBATCHMODE?
}
print("The macro took this many seconds...")
print((getTime()-start)/1000);
}
PROBLEM #1 -
If setBatchMode(true)is commented out, the macro runs with no problems.
However, using setBatchMode(true) gives the following exception, and
the macro doesn't run correctly:
java.lang.NullPointerException
at ij.plugin.filter.EDM.doWatershed(EDM.java:534)
at ij.plugin.filter.EDM.run(EDM.java:55)
at ij.IJ.runFilterPlugIn(IJ.java:179)
at ij.IJ.runPlugIn(IJ.java:111)
at ij.Executer.runPlugIn(Executer.java:168)
at ij.Executer.runCommand(Executer.java:131)
at ij.Executer.run(Executer.java:63)
at ij.IJ.run(IJ.java:311)
at ij.IJ.run(IJ.java:288)
at ij.macro.Functions.doRun(Functions.java:458)
at ij.macro.Functions.doFunction(Functions.java:53)
at ij.macro.Interpreter.doStatement(Interpreter.java:186)
at ij.macro.Interpreter.doBlock(Interpreter.java:493)
at ij.macro.Interpreter.doStatement(Interpreter.java:222)
at ij.macro.Interpreter.doFor(Interpreter.java:439)
at ij.macro.Interpreter.doStatement(Interpreter.java:204)
at ij.macro.Interpreter.doBlock(Interpreter.java:493)
at ij.macro.Interpreter.runMacro(Interpreter.java:101)
at ij.macro.MacroRunner.run(MacroRunner.java:67)
at java.lang.Thread.run(Unknown Source)
I think it's crashing at the watershedding step.
PROBLEM #2 -
I'm probably missing something obvious here. I'd like to save the
binary file that is produced by the macro with a
_bin suffix, so the original .tif isn't clobbered.
run("Tiff...", "save=["+path+"]_bin");
doesn't work.
Thanks,
Ted Lewis
--
Ted Lewis
PhD Candidate
Climate System Research Center
Department of Geosciences
University of Massachusetts at Amherst
413-545-0659
http://www.geo.umass.edu/gradstud/lewist/
|
|