Open xp1632 opened 9 months ago
@Plugin
annotation would be automatically processed by javac compiler, which generates the metadata in class bytecodeGaus.class
, with ij.plugin().addPlugin
// The @Plugin annotation is processed by the javac compiler,
// which is used to generate the metadata in class bytecode.
// Unfortunately, the Groovy compiler doesn't invoke the javac
// compiler, so we need to register the plugin manually!
GausInfo = new PluginInfo(Gaus.class, Command.class)
ij.plugin().addPlugin(GausInfo)
GausInfo
Plugin
Info when it's added successfully:
import org.scijava.command.Command;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.ui.UIService;
import org.scijava.plugin.PluginInfo
GaussFilteringClass = Class.forName("com.mycompany.imagej.GaussFiltering")
// we name it seperately bacause Groovy would interpret dot notation as object's property
// also remember to add package name before your plugin name
GausInfo = new PluginInfo(GaussFilteringClass, Command.class)
ij.plugin().addPlugin(GausInfo)
GausInfo
com.mycompany.imagej
, class name is GaussFiltering
grey_img
grey_img = ij.io().open("https://i.stack.imgur.com/B2DBy.jpg")
// Create a map with the input parameters
Map<String, Object> inputs = new HashMap<>();
inputs.put("currentData", grey_img); // replace 'dataset' with your actual Dataset
// Execute the GaussFiltering command
CommandModule module = ij.command().run(GaussFilteringClass, true, inputs).get();
We have a simpler version of hello world
command:
command defination
// 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
- **Command Execution**
// 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")]
---
For adding and registering plugin, we need:
For executing plugin, we need:
1. Initialization of ImageJ context:
the imageJ gateway is connected
2. Now we have two ways of adding the content of plugins:
You may check the customized plugin illustration here
import java.io.File; import java.util.ArrayList; import java.util.List;
@Plugin(type = Command.class, menuPath = "Plugins>Gauss Filtering") public class Gaus<T extends RealType> implements Command {
}
%classpath add jar 'E:/example-imagej2-command/target/GaussFiltering-0.1.0-SNAPSHOT.jar' // Import a class from the jar import com.mycompany.imagej.GaussFiltering
// If the import is successful, the jar has been added to the classpath println("Jar has been added to the classpath successfully.")