Skip to content

Instantly share code, notes, and snippets.

@frauzufall
Last active September 26, 2017 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frauzufall/b2978a76e9b9d1685ebeb831dd59682f to your computer and use it in GitHub Desktop.
Save frauzufall/b2978a76e9b9d1685ebeb831dd59682f to your computer and use it in GitHub Desktop.

Where to find and add algorithms in ImageJ

If you are as confused as I am about how to distinguish algorithms, scripts, macros, plugins, ops, commands and modules, welcome to this page.

TODO needs a class hierarchy view

Space of action

ImgLib2 algorithms

What?

  • ImgLib2 is a general-purpose, multidimensional image processing library and includes a bunch of algorithms. These are static methods for image processing.

How?

  • TODO Best practice how to contribute here? Is there a sandbox as suggested in imglib/imglib2#40 ?

Where?

Scijava Modules

What?

  • A module is an encapsulated piece of functionality with inputs and outputs. *
  • There are several types of modules, including plugins and scripts, as well as workflows, which are directed acyclic graphs consisting of modules whose inputs and outputs are connected. *
  • Any command can be expressed as a module (via the imagej.command.CommandModule adapter class) *
  • Not all modules are commands. The plugin service will automatically discover all available commands, whereas non-command modules are not necessarily discoverable automatically (though some might be; and it is possible to register modules with the module service manually as well). *
  • Any command can be expressed as a module (via the imagej.command.CommandModule adapter class). However, not all modules are commands. There are two services for working with modules and commands respectively. *
  • As a rule of thumb, the module service is more "low-level" while the command service is more "high-level". *

How?

Where?

  • You can ask ImageJ's module service for a list of available modules.
final List<ModuleInfo> modules = ij.module().getModules();

ImageJ Scripts

What?

  • Scripts are modules implemented in different languages that can be created, edited and executed via the Script Editor.
  • They can also be added to the Plugins menu

How?

Where?

ImageJ Macros

What?

  • A macro is a simple program that automates a series of ImageJ commands. *
  • Macros are scripts written in ImageJ's Java-like macro language, are stored in .txt files. *
  • Macros can be used to
    • automate repetitive tasks
    • document what you did
    • share common procedures
    • add tools to the toolbar
    • add keyboard shortcuts
  • Macros have a major limitation compared to the other scripting languages: they have only a fixed set of built-in functions

How?

Where?

SciJava Ops

What?

  • "write once, run anywhere"
  • Ops are a very general definition of something with a defined input and output.
  • Scijava ops should house the general, non-image-specific core, which currently resides in ImageJ Ops.

ImageJ Ops / Plugins

What?

  • An op is just an ImageJ module, but with some additional structure and requirements: you can think of an op as a function which takes a list of typed inputs, produces a list of typed outputs, and has no side effects *
  • Conceptually, a plugin is a new piece of functionality added to ImageJ. Nearly all aspects of ImageJ are pluggable, meaning plugins can be provided ad hoc to perform specified functions. The ImageJ core needs only know what general operations are available; then when the program is running, the options for how to complete a requested operation will be determined by which plugins are available at that time.
  • An op is a plugin if you annotate it accordingly
  • About: http://imagej.net/ImageJ_Ops
  • Connection to KNIME (Ops can be nodes, in KNIME all algorithms are Ops)

How?

Where?

ImageJ Special Ops

If you want to write ImageJ Ops it is helpful to note that there are a bunch of different special op classes (net.imagej.ops.special.SpecialOp).

SciJava Commands

  • Commands are plugins that are executable. These plugins typically perform a discrete operation, and are accessible via the application menus. [*](Commands are plugins that are executable. These plugins typically perform a discrete operation, and are accessible via the application menus.)
  • Whereas Services provide internal functionality, Commands are plugins designed to be executed as one-offs, typically interacting with users to achieve some desired outcome. When opening the ImageJ GUI, Commands are what populate your menu structure: exposing functionality and algorithms in a way that can be consumed by non-developers. *
  • Ops provide a reusable set of image processing algorithms.

ImageJ Commands

  • A "command" is a particular type of ImageJ plugin (implementing imagej.command.Command) which is executable (i.e., also implements the Runnable interface).
  • TODO What is the difference between ImageJ Command and SciJava Command?

Face-offs

Imglib2 functions vs Ops

Static methods can neither be overridden nor augmented in third-party libraries. Ops can be overridden.

Macros vs Plugins

Macros, written in ImageJ's Java-like macro language, are stored in .txt files. Plugins and macros are loadable code modules that extend the capabilities of ImageJ. Plugins are written in the Java programming language and compiled to .class files. Plugins run faster and are more flexible but macros are easier to write and debug. *

Modules vs Commands

If you want to expose ImageJ functionality from your software, your best bet is to work with modules rather than commands, since as stated above, not all modules are commands. *

How to know what to do

To look for existing algorithms, ImageJ's search page is a good start.

To write your own algorithms make clear if you want to..

  • .. add a static function foo to process image data?
    • is it very general (not complex)?
      • yes:
        • add foo to imglib2-algorithm
        • add an Op to wrap foo
        • TODO: when and how to annotate it as Plugin?
      • no:
        • write Op
        • TODO: when and how to annotate it as Plugin?
  • .. record or document a complete project workflow?
    • use Macros
    • check out KNIME

Related resources:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment