Converting an ImageJ Macro to a plugin

plugin
macro
Tags: #<Tag:0x00007fd547bb21e0> #<Tag:0x00007fd547bb2000>

#1

I’d like to convert a large ImageJ Macro (1200lines) to a plugin. I’ve looked around the documentation, but all I can find about writing plugins is for Java. I’m a seasoned Java developer, but not really looking forward to rewriting 1200 lines of Macro code to Java. Is there any way to ease into that, for instance by running the macro code from within the plugin?


#2

Good day Martin Van Dijken,

there is little hope for another approach than rewriting the macro in Java. The Recoder may help however. It can record macros and Java code as well as code for other scripting languages. My personal impression is that there is little difference in effort between the scripting languages (not the macro language) and Java.

Good luck

Herbie


#3

Thanks for the answer Herbie, even though that was not what I was looking for :wink:

So you can confirm it is only possible to write Plugins in a JVM language such as Java?


#4

ImageJ-plugins are written in Java.
To write plugins the ImageJ-1 way is really easy. Have a look at:
https://imagingbook.files.wordpress.com/2013/06/tutorial171.pdf

Most of ImageJ consists of plugins, even if it doesn’t look like this at the first glance. It has to do with the idea of modularity …

Regards

Herbie


#5

In the strict sense of “plugin”, yes, because it is defined as a Java class implementing ij.plugin.PlugIn (for ImageJ 1.x) or org.scijava.plugin.Plugin (and org.scijava.command.Command, for that matter, in ImageJ2/SciJava).


But really, there’s no need at all to go down that route.

You can have (almost) all the functionality with any of the supported scripting languages, and you can even implement plugin classes using Jython or Groovy.


But let me first ask: why do you think you have to convert your macro? Are you missing some functionality? If it is just for unit testing, version management, and/or continuous integration, you can simply include all your scripts in a single jar file, as illustrated by this project:


As a first step to make a 1200-line macro more managable, I’d suggest to split it into different functional units that each perform a specified task (either as functions within the same file, or as separate files).

If you elaborate a bit on your use case, and maybe post your macro here, someone here on the forum can help you more specifically.