Skip to content

Instantly share code, notes, and snippets.

@ctrueden
Created October 15, 2020 14:36
Show Gist options
  • Save ctrueden/c4252a29d1b2aad6e0edf8cd290e05b0 to your computer and use it in GitHub Desktop.
Save ctrueden/c4252a29d1b2aad6e0edf8cd290e05b0 to your computer and use it in GitHub Desktop.
2020-10-15 ImageJ2.js meeting notes
#@ CommandService cs
#@ ModuleService ms
#@ ScriptService ss
modules = ms.getModules() // get all modules!
future = ms.run(modules[0], true, listOrMapOfArguments)
// if you want to block till completion:
m = future.get()
outputs = m.getOutputs() // is a dict
// How to convert numpy array to/from ImageJ image types?
// In PyImageJ, here is what we do:
// - numpy array <-> RandomAccessibleInterval ... specifically ReferenceGuardedRandomAccessibleInterval
// from imglib2-unsafe which wraps a memory pointer
// The types match up... numpy float64 == ImgLib2 DoubleType for example
// - xarray object <-> net.imagej.ImgPlus ... because ImgPlus has axis metadata and so forth, like xarray does
// ImgPlus is a wrapper around a net.imglib2.Img, which is an extension of RandomAccessibleInterval
// in Python, xarray *has* a numpy array plus metadata
// in Java, ImgPlus *has* an Img (metadata-free image data) plus metadata
// The code is:
// https://github.com/imagej/pyimagej/blob/45f167d6374c05b3540537d6be673ea2fcb6e1b1/imagej/imagej.py#L378-L392
//
// Won't work exactly as is for you but it shows the mapping.
//
// The ReferenceGuardedRandomAccessibleInterval / imglib2-unsafe wraps the numpy array BY REFERENCE.
// It just reuses the same memory pointer. So NO COPY.
// ImgLib2 is totally interface-driven, and you create accessors (called Cursor or RandomAccess objects) on your
// image. An image *does not have* a current position. Only the accessors do.
//
// zarr and dask are duck typed images... they _are not_ strictly speaking numpy arrays.
// So... this PyImageJ mechanism WON'T WORK with them.
// Imglyb (the layer that wraps the image data) requires a pointer to contiguous memory.
// For the RPC, you'll need an implementation of the RandomAccessibleInterval interface that uses
// RPC calls to obtain the answer to the caller's requests.
// Image Types to be aware of:
// net.imagej.Dataset
// net.imagej.ImgPlus
// net.imglib2.Img
// net.imglib2.RandomAccessibleInterval
// net.imagej.DatasetView -- wraps a Dataset but with visualization metadata e.g. color maps, display min/maxes
// net.imagej.ImageDisplay -- a collection of DataView (DatasetView extends DataView)
// SciJava has the concept of *modules*
// - a module is a function, with typed inputs and typed outputs
// - a module though is not a SciJava *plugin*
// a *plugin* is any Java class that implements the SciJavaPlugin interface
// and is annotated with @Plugin(type = MyTypeOfPlugin.class)
// there are many kinds of plugins
// one kind of plugin is the SciJava Command. org.scijava.command.Command interface
// Many things in ImageJ are classes that implement this interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment