imagej / pyimagej

Use ImageJ from Python
https://pyimagej.readthedocs.io/
Other
474 stars 82 forks source link

Make it possible to spin up ImageJ without a local installation present #9

Closed ctrueden closed 5 years ago

ctrueden commented 6 years ago

The imagej module could invoke jrun to download all of net.imagej:imagej, instead of relying on a user installation of ImageJ or Fiji. Then we can add an alternate API method to create a wrapped net.imagej.ImageJ instance without requiring a local installation of ImageJ or Fiji.

This is what @hanslovsky does in imglyb:

    primary_endpoint, workspace = jrun.jrun.resolve_dependencies(
        '+'.join([IMGLIB2_IMGLYB_ENDPOINT] + imglyb_config.get_endpoints()),
        cache_dir=IMGLYB_JAR_CACHE_DIR,
        m2_repo=LOCAL_MAVEN_REPO,
        repositories=imglyb_config.get_repositories(),
        verbose=2
    )
    jnius_config.add_classpath(os.path.join(workspace, '*'))

@hanslovsky wrote:

Replace imglyb_config.get_endpoints() with [endpoint1, endpoint2, ...], endpointN in the sense of jrun endpoints. In some sense, jrun is now what scyjava was supposed to be (without adding new jars at runtime, though), cf scijava/scyjava#3.

See also this discussion on forum.image.sc.

We need to make sure to fulfill the following use cases:

  1. Ability to spin up the latest release version of net.imagej:imagej.

  2. Ability to spin up an explicitly specified version of net.imagej:imagej, for reproducibility.

  3. Ability to mix in other JAR files so that your ImageJ can have desired plugins. The jrun syntax is already flexible enough for this using the + symbol; we also have components like sc.fiji:fiji that it would be nice to be able to execute directly to include all of its goodies.

ctrueden commented 5 years ago

And here is how to do it with the newly released scyjava 0.1.0, which uses jgo (the artist formerly known as jrun) under the hood:

>>> import scyjava_config
>>> scyjava_config.add_repositories({'imagej.public': 'https://maven.imagej.net/content/groups/public'})
>>> scyjava_config.add_endpoints('net.imagej:imagej:2.0.0-rc-65')
>>> import scyjava, jnius
>>> System = jnius.autoclass('java.lang.System')
>>> System.setProperty('java.awt.headless', 'true')
>>> ImageJ = jnius.autoclass('net.imagej.ImageJ')
>>> ij = ImageJ()
>>> formula = "10 * (Math.cos(0.3*p[0]) + Math.sin(0.3*p[1]))"
>>> blank = ij.op().create().img([64, 16])
>>> sinusoid = ij.op().image().equation(blank, formula)
>>> print(ij.op().image().ascii(sinusoid))
,,,--+oo******oo+--,,,,,--+oo******o++--,,,,,--+oo******o++--,,,
...,--+ooo**oo++--,....,,--+ooo**oo++-,,....,,--+ooo**oo++-,,...
 ...,--++oooo++--,... ...,--++oooo++--,... ...,--++oooo++-,,...
   ..,--++++++--,..     ..,--++o+++--,..     .,,--++o+++--,..
   ..,,-++++++-,,.      ..,,-++++++-,,.      ..,--++++++-,,.
    .,,--++++--,,.       .,,--++++--,,.       .,,--++++--,..
    .,,--++++--,,.       .,,-+++++--,,.       .,,-+++++--,,.
   ..,--++++++--,..     ..,--++++++--,..     ..,--++++++-,,..
  ..,,-++oooo++-,,..   ..,,-++oooo++-,,..   ..,,-++ooo+++-,,..
...,,-++oooooo++-,,.....,,-++oooooo++-,,.....,,-++oooooo+--,,...
.,,,-++oo****oo++-,,,.,,,-++oo****oo+--,,,.,,,-++oo****oo+--,,,.
,,--++o***OO**oo++-,,,,--++o***OO**oo+--,,,,--++o***OO**oo+--,,,
---++o**OOOOOO**o++-----++o**OOOOOO*oo++-----++o**OOOOOO*oo++---
--++oo*OO####OO*oo++---++oo*OO####OO*oo++---++o**OO####OO*oo++--
+++oo*OO######O**oo+++++oo*OO######O**oo+++++oo*OO######O**oo+++
+++oo*OO######OO*oo+++++oo*OO######OO*oo+++++oo*OO######OO*oo+++