// Behind a firewall? Configure your proxy settings here. //System.setProperty("http.proxyHost","myproxy.domain") //System.setProperty("http.proxyPort","8080") //System.setProperty("https.proxyHost","myproxy.domain") //System.setProperty("https.proxyPort","8080") // Load the ImageJ library from the remote Maven repository. %classpath config resolver scijava.public https://maven.scijava.org/content/groups/public %classpath add mvn net.imagej imagej 2.0.0-rc-71 // OR: Load ImageJ with Fiji plugins from the remote Maven repository. //%classpath config resolver scijava.public https://maven.scijava.org/content/groups/public //%classpath add mvn sc.fiji fiji 2.0.0-pre-10 // OR: Load ImageJ with Fiji plugins from a local Fiji installation. //%classpath add jar '/Applications/Fiji.app/jars/*' //%classpath add jar '/Applications/Fiji.app/jars/bio-formats/*' //%classpath add jar '/Applications/Fiji.app/plugins/*' // Create an ImageJ gateway. ij = new net.imagej.ImageJ() "ImageJ v${ij.getVersion()} is ready to go." // The plugin service manages the available plugins (see "Plugins" below). pluginCount = ij.plugin().getIndex().size() println("There are " + pluginCount + " plugins available.") // The log service is used for logging messages. ij.log().warn("Ignoring negative sigma value.") // The status service is used to report the current status of operations. // Within a notebook like this, the call does not do anything visible. ij.status().showStatus("Processing data file 34 of 97...") // The menu service organizes a menu hierarchy for modules (see "Modules" below). menuItemCount = ij.menu().getMenu().size() println("There are " + menuItemCount + " menu items total.") // The platform service handles platform-specific functionality. // E.g., it can open a URL in the default web browser for your system: // ij.platform().open(new URL("https://imagej.net/")) myList = ["quick", "brown", "fox"] ij.notebook().methods(myList) ij.notebook().methods(ij).findAll{ it.get("returns").endsWith("Service") } // Gather a count of each kind of plugin. kindCounts = [:] ij.plugin().getPlugins().forEach{plugin -> kind = plugin.getPluginType().getName() // HACK: Report all Op plugin subtypes as simply "Op", to avoid overwhelming the list. if (kind.startsWith('net.imagej.ops.Ops') || kind.startsWith('net.imagej.ops.features')) kind = 'net.imagej.ops.Op' kindCounts.put(kind, kindCounts.getOrDefault(kind, 0) + 1) } // Build a table which reports this information nicely. kindCounts.keySet().sort().stream().map{kind -> [ "package": (kind =~ /^.*\./)[0][0..-2], "class": (kind =~ /\.[^\.]*$/)[0][1..-1], "count": kindCounts.get(kind) ]}.collect() snowflake = ij.io().open("https://imagej.net/images/snowflake.gif") destPath = System.getProperty("user.home") + "/Desktop/snowflake.png" ij.io().save(snowflake, destPath) "Saved to '$destPath'; length = ${new File(destPath).length()}" // Write the script as a string constant, so it can be passed to the script service. script = """ #@input String name #@output String greeting #@output int length greeting = "Hello, " + name + "!" length = name.length() """ // Run the script, passing input key/value pairs using a map. inputs = ["name": System.getProperty("user.name")] module = ij.script().run("greeting.groovy", script, true, inputs).get(); // Extract the module output values. ["greeting" : module.getOutput("greeting"), "length" : module.getOutput("length")] // NB: While this is a Groovy cell, the class definition here is valid Java. import org.scijava.ItemIO; import org.scijava.command.Command; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; @Plugin(type = Command.class) public class Hello implements Command { @Parameter private String name; @Parameter(type = ItemIO.OUTPUT) private String greeting; @Parameter(type = ItemIO.OUTPUT) private int length; @Override public void run() { greeting = "Hello, " + name + "!"; length = name.length(); } } // Save a reference to the class, for use in the next cell. greetingCommand = Hello.class // Run the command, passing input key/value pairs using a map. inputs = ["name": "John Jacob Jingleheimer Schmidt"] module = ij.command().run(greetingCommand, true, inputs).get() // Extract the module output values. ["greeting" : module.getOutput("greeting"), "length" : module.getOutput("length")] modules = [] ij.module().getModules().stream().map{module -> [ "id": module.getIdentifier(), "location": module.getLocation().replaceAll('.*/(.*\\.jar)$', '$1'), "version": module.getVersion() ]}.collect()