Running macro from command line in window


First of all, i would like to thank ImageJ community for such a big support.

Currently, i have successfully made macro to process all of my images in batch mode. However, i would like to speed the process up a little bit by running this macro in headless mode. I knew that this question have been asked several times already. However, i still couldn’t figure it out how to fix the error. I’m wondering if someone could help me with this problem. Thank you :slight_smile:


// @File(label = "Input directory", style = "directory") dir1
// @String (label = "[Polar]Image Size in pixels") Size
// @String (label = "[Wavelet-FFT]Damping Coefficient",) Damping
// @string (label = "[Wavelet-FFT]Wavelet Specification", choices = {"DB10","DB11","DB12","DB13","DB14","DB15","DB16","DB17","DB18","DB19","DB20","DB21","DB22","DB23","DB24","DB25","DB26","DB27","DB28","DB29","DB30","DB31","DB32","DB33","DB34","DB35","DB36","DB37","DB38","DB39","DB40"}) Wavelet
// @string (label = "[Wavelet-FFT]Decomposition ID, [A:B] format") ID
// @string (label = "Old Name") Oldname
// @string (label = "New Name") Newname

// Requried Plugin
//				- Xlib
//				- Polar Transformer

extension = ".tif"; //File type
setBatchMode(true);// Process the data without opening images
count =0;
Countfiles (dir1);
n = 0;
print(count + " files processed");
//Count number of Data, which will be used to show the progress bar
function Countfiles(dir1) {
list = getFileList(dir1);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], "/"))
Countfiles(""+dir1+ File.separator +list[i]);
//Find the images within subfolder, as well as making progress bar
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);

//Batch process the iamges

function processImage(dir1, name) {
open(dir1 + File.separator + name);

//Put your code in the following
Lines = PI*Size/2;
run("Polar Transformer", "method=Polar degrees=180 default_center number=Lines");
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");"
run("Polar Transformer", "method=Cartesian degrees=180 default_center");
//Save images
SaveName = replace(name, Oldname, Newname);
 saveAs("Tiff", dir1+ File.separator+ SaveName);

 while (nImages>0){
	selectImage (nImages);


This is what i executed in window command line

> C:\Users\KAEDE>C:\Users\KAEDE\Desktop\\ImageJ-win64.exe --headless --console -macro C:\Users\KAEDE\Desktop\\scripts\Plugins\CT_RingArtifectRemoval.ijm 'dir1=C:\Users\KAEDE\Desktop\Mo\17071913\04slice, Size=700, Damping=2, Wavelet=DB16, ID=0:2, Oldname=rec, Newname=RA'

Dear @Chatcharit_Kiattisak,

Are there any errors when you execute the macro? What exactly is your question here?


Dear @stelfrich,

I’m so sorry for not making it clear. I try to pass the parameters from the command line to my macro. but, when i executed in the command line. i got an error.
This is the massage

C:\Users\KAEDE>Java HotSpot™ 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot™ 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release
8 21, 2017 8:18:10 午後 java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(…) returned error code 5.
Macro Error: Undefined variable in line 17.

Countfiles ( ) ;
Unsupported format or not found
Unsupported format or not found
Unsupported format or not found
Unsupported format or not found
Unsupported format or not found
Unsupported format or not found

I don’t know what i did wrong. I’m wondering if you could point out what the problem might be.

Best regards,


The -macro option of the launcher doesn’t parse the script parameters that you are using in your macro. It works properly for ImageJ1 macros that don’t use any ImageJ2/SciJava functionality (like script parameters). Instead, you can use the --run option. Try the following:

C:\Users\KAEDE\Desktop\\ImageJ-win64.exe --ij2 --headless --console --run C:\Users\KAEDE\Desktop\\scripts\Plugins\CT_RingArtifectRemoval.ijm  'dir1="C:\Users\KAEDE\Desktop\Mo\17071913\04slice",Size=700,Damping=2,Wavelet="DB16",ID="0:2",Oldname="rec",Newname="RA"'

Please mind that you have to wrap Strings in double quotes (scroll to the end of the previous line).

You can get further information on scripts/macros in headless mode: