Headless mode and directory input

Hi, I have a macro that I am trying to run in headless mode. I’m very new to setting this up and on Friday managed to get it to run I now think through some X11 setting I played with in trying to set (java.awt.headless=true). I am thinking this because in getting it to work… I have the graphical screen to navigate to the directories of choice.

Is there a way to write code such that you can provide path information for directories as you run the code?

My Macro takes files from one directory- processes them and defines an ROI… saves this ROI and applies it to an image in second directory with the same base string name , takes some measurements, then saves the data in a third directory.

I can see the “Start directory loop” in terminal so I know the code starts… My macro currently starts like this…

// Macro code for batch processing a folder
// of .tif files, includes saving .tifs back into the 
// ORIGINAL folder with a modified version 
// of the original image name
print("start directory loop");
dir = getDirectory("Choose input segment Directory ");      // prompts the user to select the folder to be processed, 
                                                            // stores the folder as the destination for saving
list = getFileList(dir);                                    // gives ImageJ a list of all files in the folder to work through
print("number of files in dir1 Segments",list.length);               // optional prints the number of files in the folder

dir2 = getDirectory("Choose input Image Directory "); // promts user to select folder to be saved in
list2 = getFileList(dir2);                 // gives ImageJ a list of all files in the folder to work through for directory2 
extension2 = ".tif";   //defines file type  variable 
print("number of files in dir2 Image",list2.length);                       // optional prints the number of files in the folder

dir3= getDirectory("Choose output Directory"); //promts user to select folder on Images for Results

setBatchMode(true);               // runs up to 6 times faster, without showing images onscreen.  Turn off during troubleshooting steps??

Thanks for any help!

Dear Susan,

you could use the @Parameter annotation for defining parameters (i.e. folders) of your macro. That way, you get the added bonus of being able to pass those paramters to a headless instance of ImageJ(2).

I have described a sample script in another thread that you could take a look at (as well as the documentation page). You can subsequently pass the arguments to the macro via the command line:

$ ./ImageJ-macosx --ij2 --headless --console --run FooBar.ijm "srcDir=/Users/foo/bar/,dstDir=/Users/bar/foo/"

For more details, consult the Wiki page on ImageJ’s headless mode.

Best,
Stefan

3 Likes