MIJI call macro with arguments

Hi,
I have an ImageJ macro (written by someone else) which is pasted in ImageJ’s StartUpMacros.txt. The macro (called StackReg-average-stackreg_Stacks) requires that a directory is specified before it can run.

I am trying to run the macro from Matlab using MIJ, but I would like to completely automate the process so that I input the directory path via an argument rather than with a pop-up browse specification. The problem is that I cannot seem to get the syntax right.

I have tried:

javaaddpath 'C:\Program Files\MATLAB\R2015a\java\jar\mij.jar'.
javaaddpath 'C:\Program Files\MATLAB\R2015a\java\jar\ij.jar'.

MIJ.start('C:\Users\Gabi1\Downloads\ij150-win-java8\ImageJ\plugins');

with various combinations of

  1. MIJ.run('Open...', strcat('path=',RepsPath,'')) - this produces an error:

     Unsupported format or not found
     File is not in a supported format, a reader plugin is not available, or it was not found. 
    
  2. MIJ.run('StackReg-average-stackreg_Stacks');

I have also tried specifying the directory as an argument and then commenting out the first line of the macro.
e.g.

MIJ.run('StackReg-average-stackreg_Stacks', strcat('dir1=',RepsPath,''));
MIJ.run('StackReg-average-stackreg_Stacks', strcat('dir1=getDirectory(',RepsPath,')'));

Although these options does not produce errors, they also does not run the macro.

For completeness sake, here is a copy of the macro:

// Macro to StackReg-average a set of stacks
  macro "StackReg-average-stackreg_Stacks"
 {

      // prompt user for source directory
      dir1 = getDirectory("Choose Source Directory ");

      // read in file listing from source directory
      list = getFileList(dir1);

list1 = getFileList(dir1+list[0]);



	// Open the first file in the directory
	run("Image Sequence...", "open=["+dir1+list[0]+"] number=1 starting=1 increment=1 scale=100 file=[] or=[] sort")

	width=getWidth();
	height=getHeight();

	run("Close");

	newImage("AlignAvg", "32-bit Black", width, height, list1.length);

  for (j=1; j<=list1.length; j++)  {

         for (i=0; i<list.length; i++) {
	listcurr = getFileList(dir1+list[i]);

run("Image Sequence...", "open=["+dir1+list[i]+"] number=1 starting="+j+" increment=1 scale=100 file=[] or=[] sort");
	

//open(listcurr[j]);
	}

run("Images to Stack");

		 run("StackReg ", "transformation=[Rigid Body]");

    run("32-bit");

		 run("Z Project...", "start=1 stop="+list.length+" projection=[Average Intensity]");

		 run("Select All");
		 run("Copy");
		 selectWindow("AlignAvg");
		 setSlice(j);
		 run ("Paste");
		 selectWindow("AVG_Stack");
		 run("Close");
		 selectWindow("Stack");
		 run("Close");
}

selectWindow("AlignAvg");
     run("StackReg ","transformation=[Rigid Body]");
     rename("AlignAvgAlign");


}

I would really appreciate any help you could offer.
Cheers,
Gabi

Welcome to the forum, @Gabi1!

Please note that MIJ is an unsupported legacy project. Instead, please check out the MATLAB Scripting feature of ImageJ2. You will need to enable the MATLAB update site. Then you can use parameterized scripts to write MATLAB code with declared inputs and outputs, which can be executed from ImageJ1 macros, including headless from the command line. (/cc @hinerm)