xp1632 / VPE_IP

0 stars 0 forks source link

How to make a customized command plugin for Fiji ImageJ? #35

Open xp1632 opened 9 months ago

xp1632 commented 9 months ago
xp1632 commented 9 months ago

https://imagej.net/develop/plugins

xp1632 commented 9 months ago

What's a plugin?

@Plugin(type=Service.class)
public class MyService implements Service { }

Plugin priority

@Plugin(priority=224)
public class SpecialService implements Service { }
xp1632 commented 9 months ago

SciJava plugin framework:

- Typically ImageJ plugin developers will be writing :

@Plugin
public class MyPlugin {

  // This @Parameter notation is 'asking' the Context
  // for an instance of LogService.
  @Parameter
  private LogService logService;

  public void log(String message) {
    // Just use the LogService!
    // There is no need to construct it, since the Context
    // has already provided an appropriate instance.
    logService.info(message);
  }
}
xp1632 commented 9 months ago

- Reason that new Myplugin() we used doesn't work:

public class MyService {

  // This service will manually create plugin instances
  // So, we need a reference to our containing Context
  // Then we can use it to inject our plugins.
  @Parameter
  private Context context;

  public void doStuff() {
    // Manually create a plugin instance
    // It is not connected to a Context yet
    MyPlugin plugin = new MyPlugin();

    // Inject the plugin instance with our Context,
    // so the logService field of the plugin will be
    // populated.
    context.inject(plugin);

    // Now that our plugin is injected, we can use
    // it with the knowledge that its parameters
    // have been populated
    plugin.log("Success!");
  }
}
xp1632 commented 9 months ago

Services Plugins in SciJava :

Plugin Service

https://github.com/scijava/scijava-common/blob/scijava-common-2.47.0/src/main/java/org/scijava/plugin/PluginService.java

Plugin Manual Register on jupyter:

after registration then we can execute our op:

// Execute our Op and get the result
result = ij.op().run("narf", "Put some trousers on")

The ij.plugin().addPlugin() is from the PluginService in SciJava framework

xp1632 commented 9 months ago

- Command Plugins in SciJava


This way, input harvest is decoupled from functional operation

xp1632 commented 9 months ago

Plugins reference repository:

xp1632 commented 9 months ago

Now we show the real development process of a ImageJ2 plugin:

1. plugin template for imageJ2 : https://github.com/imagej/example-imagej2-command

2. Read and edit the plugin content GaussFilter.java

Import Part



@Plugin @Parameter Annotation part

image


main() for fast testing image

xp1632 commented 9 months ago

Gaussian Filter Plugin illustration:

- In run() method,


- In main() method image

xp1632 commented 9 months ago

3. Export customized Plugin into a jar file:

To build a Maven project into a JAR file in Visual Studio Code, you can use the integrated terminal and the Maven command line tool. Here are the steps:

  1. Open the integrated terminal in Visual Studio Code. You can do this by going to the View menu and selecting Terminal, or by pressing `Ctrl+`` (backtick).

  2. Navigate to the root directory of your Maven project (the directory that contains the pom.xml file). You can do this with the cd command. For example, if your project is in a directory called my-project, you would type cd my-project.

  3. Run the mvn package command. This command will compile your code, run any tests, and package the compiled code into a JAR file. The JAR file will be created in the target directory of your project.

image