Advice on troubleshooting a Macro: Plugin not running as expected

Hi everyone,

I am new to writing code (in general, as well as) in Macro scripting language, and could use your advice/help.

What I want to do: I want to run a plugin called Differentials JB with a specific operation of differentiate with respect to X or differentiate with respect to Y on 32-bit gray scale images that I have stored in a folder.

Steps in the Macro: I modified the code generated by the recorder macro option to write a macro. Specifically, for a list of files from a user selected folder, the macro loops through each file and does the following:

  1. Open an image.
  2. Duplicate the opened image.
  3. Run a plugin called Differentials JB with the operation set to Differ_X option - i.e. run(“Differentials JB”, “operation=DIFFER_X”);
  4. Resize the image - i.e. run(“Resize Canvas”, “width=240 height=240 position=Center zero”);
  5. Save the output image.
  6. Repeat steps 2-5 with plugin Differentials set to Differ_Y option - i.e. run(“Differentials JB”, “operation=DIFFER_Y”);
  7. Close all.

Issue/Problem: When I run the macro, the output images are not the same as what I get when I manually perform the steps (described above). On using the Debug macro option, I could identify the line that is causing the problem. It appears that when the macro runs the plugin (Differentials JB), it does not apply the operation setting as mentioned in the macro. The macro uses either the default or last used operation setting (i.e. if I opened ImageJ and then run the macro, the plugin Differentials JB uses the default operation setting instead of switching to operation=Differ_X setting as written in the macro. If I manually used Differentials JB with Differ_X operation setting, and then run the macro, the plugin Differentials JB uses operation=Differ_X setting for all the images processed by the macro).

I do not know how to rectify this problem. The line “run(“Differentials JB”, “operation=DIFFER_X”);” was obtained from the recorder macro option, so I do not believe the command is incorrect. I appreciate any help or advice on how to proceed from here. Thank you in advance.

1 Like

Hey @pixiescientist,

would you mind sharing the macro you tried? We can then have a look together :wink:

Furthermore, I’m not aware of the Differentials JB plugin you mentioned. Where did you get it from?


Hi @haesleinhuepf

Sure, here is the code:

dir = getDirectory("Choose the directory with input files");
list = getFileList(dir);
outputDir = getDirectory("Directory to save processed images");
  if (outputDir=="")
      exit("No directory available for saving.");
for (i=0; i<(list.length); i++) {
t1 = getTitle();
run("Duplicate...", " ");
run("Differentials JB", "operation=DIFFER_X");
run("Canvas Size...", "width=240 height=240 position=Center zero");
saveAs("Tiff", outputDir+t1+"_diffwrtX.tif");
run("Duplicate...", " ");
run("Differentials JB", "operation=DIFFER_Y");
run("Canvas Size...", "width=240 height=240 position=Center zero");
saveAs("Tiff", outputDir+t1+"_diffwrtY.tif");
endDialog=Dialog.create("Task completed");
Dialog.addMessage("Done. End of generateDifferenitals macro.");;

And the link to the plugin:
I am using a modified version of the plugin (Modified by someone else) that isn’t shared online as far as I know.

Hey @pixiescientist,

I just had a look and don’t see any code related to a “Differentials JB” plugin behind the link you gave. That makes it pretty hard to reproduce or explain the error. May you contact the developer of the customized version of the plugin? Maybe he/she wants to join our discussion?