A Problem with inserting string in macro


#1

Hi all,

I would like to begin with, i`m completely new to ImageJ. At the moment, i’m working on a macro, processing thousand of pictures. Basically, i would like to apply 3 filters to my images and save to individual folders. For the easy usage, i put all the important variable in the input function. However, the problem with this macro is that, there are some variables doesn’t work properly (Wavelet, ID). I noticed that these two variables contains text and number together, which might cause the problems. Does anybody have ideas what’s the problem?

Thanks a lot

// @File(label = “Input directory”, style = “directory”) dir1
// @String (label = “Number of Lines in Angle Direction”) Lines
// @String (label = “Damping Coefficient”,) Damping
// @string (label = “Wavelet Specification”, choices = {“DB10”,“DB15”,“DB20”,“DB25”,“DB30”,}) Wavelet
// @string (label = “Decomposition ID”) ID
// @string (label = “File name prefix”) Prefix

extension = “.tif”;
setBatchMode(true);
count =0;
Countfiles (dir1);
n = 0;
processFolder(dir1);
print(count + " files processed");

function Countfiles(dir1) {
list = getFileList(dir1);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], “/”))
Countfiles(""+dir1+ File.separator +list[i]);
else
count++;
}
}
function processFolder(dir1) {
list = getFileList(dir1);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], “/”))
processFolder(""+dir1+ File.separator+list[i]);
else if (endsWith(list[i], extension))
processImage(dir1, list[i]);
showProgress(n++, count);
}
}

function processImage(dir1, name) {
open(dir1 + File.separator + name);
//print(n++, name);
run(“Polar Transformer”, “method=Polar degrees=360 default_center number=Lines”);
run(“Stripes Filter”, “filter=Wavelet-FFT direction=Vertical types=Daubechies wavelet=DB15 border=[Symmetrical mirroring] image=don’t decomposition=ID damping=Damping large=100000000 small=1 tolerance=1 half=5 offset=1”);
run(“Polar Transformer”, “method=Cartesian degrees=360 default_center”);
run(“Collect Garbage”);

 saveAs("Tiff", dir1+ File.separator+ Prefix +name);
 close();

}


#2

This is the error

(Fiji Is Just) ImageJ 2.0.0-rc-61/1.51p; Java 1.8.0_66 [64-bit]; Windows 10 10.0; 120MB of 12125MB (<1%)

java.lang.NumberFormatException: For input string: "ID"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.parseInt(Integer.java:615)
at xjava.utilities.xInputArgs.parseNvariablesInt(xInputArgs.java:533)
at xStripes_Filter.stripesFilter(xStripes_Filter.java:451)
at xStripes_Filter.run(xStripes_Filter.java:252)
at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:265)
at ij.plugin.filter.PlugInFilterRunner.(PlugInFilterRunner.java:114)
at ij.IJ.runUserPlugIn(IJ.java:219)
at ij.IJ.runPlugIn(IJ.java:181)
at ij.Executer.runCommand(Executer.java:137)
at ij.Executer.run(Executer.java:66)
at ij.IJ.run(IJ.java:297)
at ij.macro.Functions.doRun(Functions.java:601)
at ij.macro.Functions.doFunction(Functions.java:96)
at ij.macro.Interpreter.doStatement(Interpreter.java:243)
at ij.macro.Interpreter.doBlock(Interpreter.java:621)
at ij.macro.Interpreter.runUserFunction(Interpreter.java:324)
at ij.macro.Interpreter.doStatement(Interpreter.java:246)
at ij.macro.Interpreter.doIf(Interpreter.java:979)
at ij.macro.Interpreter.doStatement(Interpreter.java:261)
at ij.macro.Interpreter.doIf(Interpreter.java:992)
at ij.macro.Interpreter.doStatement(Interpreter.java:261)
at ij.macro.Interpreter.doBlock(Interpreter.java:621)
at ij.macro.Interpreter.doStatement(Interpreter.java:285)
at ij.macro.Interpreter.doFor(Interpreter.java:543)
at ij.macro.Interpreter.doStatement(Interpreter.java:267)
at ij.macro.Interpreter.doBlock(Interpreter.java:621)
at ij.macro.Interpreter.runUserFunction(Interpreter.java:324)
at ij.macro.Interpreter.doStatement(Interpreter.java:246)
at ij.macro.Interpreter.doStatements(Interpreter.java:231)
at ij.macro.Interpreter.run(Interpreter.java:115)
at ij.macro.Interpreter.run(Interpreter.java:86)
at ij.macro.Interpreter.run(Interpreter.java:97)
at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
at ij.IJ.runMacro(IJ.java:134)
at ij.IJ.runMacro(IJ.java:123)
at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1052)
at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1048)
at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:999)
at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1048)
at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:136)
at org.scijava.script.ScriptModule.run(ScriptModule.java:159)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:237)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)


#3

Dear @Chatcharit_Kiattisak,

you are missing some string concatenations (+). In the following line, the contents of the variables Wavelet and ID should be used:

run("Stripes Filter", "filter=Wavelet-FFT direction=Vertical types=Daubechies wavelet="+Wavelet+" border=[Symmetrical mirroring] image=don't decomposition="+ID+" damping=Damping large=100000000 small=1 tolerance=1 half=5 offset=1");

Best,
Stefan


#4

Oh my god, it works. Thank you very much. :slight_smile: