Hard Code Folder Reference in Command Line

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Hard Code Folder Reference in Command Line

burt46
Hi

I have a IJ macro that when it opens it asks me to select the source folder where i have a bunch of images that the macro cycles through and processes.

Is there a way to select this folder directly in the command line, such as change:

start "C:\Program Files\ImageJ" imagej.exe -macro folderprocess.txt

to something like.

start "C:\Program Files\ImageJ" imagej.exe -macro folderprocess.txt "C:\Test1"

I know i can add the folder reference into the macro itself, but this means i have to change the macro each time if i change the folder destination. Basically, i am trying to automate the call function to the macro via commandline as i can dynamically create the "C:\Test1" location reference. I cant do this within an IJ macro.

Any advice greatly appreciated.
Reply | Threaded
Open this post in threaded view
|

Re: Hard Code Folder Reference in Command Line

burt46
Ok i solved this in another way using

File.openAsString(path)

This calls a text file that has the folder path on a single line.

Problem is that it sticks a " | " at the end and i cant work out why or how to get rid of it. Any ideas?

Reply | Threaded
Open this post in threaded view
|

Re: Hard Code Folder Reference in Command Line

ctrueden
In reply to this post by burt46
Hi,

Yes, you can pass parameter values to scripts using ImageJ2's headless/CLI
scripting mechanism.

See this page for details:
http://imagej.net/Scripting_Headless

Here is an example parameterized macro:

--snip--
// @File(label="Input directory") input
// @File(label="Output directory") output
// @String(label="File suffix", value=".tif") suffix

processFolder(input);

function processFolder(input) {
list = getFileList(input);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + list[i]))
processFolder("" + input + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}

function processFile(input, output, file) {
// do the processing here by replacing
// the following two lines by your own code
print("Processing: " + input + "/" + file);
print("Saving to: " + output);
}
--snap--

And example invocation from the CLI:

--snip--
/Applications/Fiji.app/Contents/MacOS/ImageJ-macosx --ij2 --headless --run
/Users/curtis/Desktop/Process_Folder.ijm
"input='/Users/curtis/data',output='/Users/curtis/outDir',suffix='.tif'"
--snap--

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - http://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - http://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Thu, Jul 21, 2016 at 12:41 PM, burt46 <[hidden email]> wrote:

> Hi
>
> I have a IJ macro that when it opens it asks me to select the source folder
> where i have a bunch of images that the macro cycles through and processes.
>
> Is there a way to select this folder directly in the command line, such as
> change:
>
> start "C:\Program Files\ImageJ" imagej.exe -macro folderprocess.txt
>
> to something like.
>
> start "C:\Program Files\ImageJ" imagej.exe -macro folderprocess.txt
> "C:\Test1"
>
> I know i can add the folder reference into the macro itself, but this means
> i have to change the macro each time if i change the folder destination.
> Basically, i am trying to automate the call function to the macro via
> commandline as i can dynamically create the "C:\Test1" location reference.
> I
> cant do this within an IJ macro.
>
> Any advice greatly appreciated.
>
>
>
> --
> View this message in context:
> http://imagej.1557.x6.nabble.com/Hard-Code-Folder-Reference-in-Command-Line-tp5016919.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html