├── .gitignore ├── README.md ├── pom.xml └── src └── main └── java └── com └── mycompany └── imagej └── GaussFiltering.java /.gitignore: -------------------------------------------------------------------------------- 1 | /.classpath 2 | /.project 3 | /.settings/ 4 | /target/ 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is an example Maven project implementing an ImageJ2 command. 2 | 3 | For an example Maven project implementing an **original ImageJ plugin**, see: 4 | https://github.com/imagej/example-legacy-plugin 5 | 6 | It is intended as an ideal starting point to develop new ImageJ2 commands 7 | in an IDE of your choice. You can even collaborate with developers using a 8 | different IDE than you. 9 | 10 | * In [Eclipse](http://eclipse.org), for example, it is as simple as 11 | _File › Import... › Existing Maven Project_. 12 | 13 | * In [NetBeans](http://netbeans.org), it is even simpler: 14 | _File › Open Project_. 15 | 16 | * The same works in [IntelliJ](http://jetbrains.net). 17 | 18 | * If [jEdit](http://jedit.org) is your preferred IDE, you will need the 19 | [Maven Plugin](http://plugins.jedit.org/plugins/?MavenPlugin). 20 | 21 | Die-hard command-line developers can use Maven directly by calling `mvn` 22 | in the project root. 23 | 24 | However you build the project, in the end you will have the `.jar` file 25 | (called *artifact* in Maven speak) in the `target/` subdirectory. 26 | 27 | To copy the artifact into the correct place, you can call 28 | `mvn -Dscijava.app.directory="/path/to/ImageJ2.app/"`. 29 | This will not only copy your artifact, but also all the dependencies. 30 | 31 | Developing code in an IDE is convenient, especially for debugging. 32 | To that end, this project contains a `main` method which launches ImageJ2, 33 | loads an image and runs the command. 34 | 35 | Since this project is intended as a starting point for your own 36 | developments, it is in the public domain. 37 | 38 | How to use this project as a starting point 39 | =========================================== 40 | 41 | 1. Visit [this link](https://github.com/imagej/example-imagej2-command/generate) 42 | to create a new repository in your space using this one as a template. 43 | 44 | 2. [Clone your new repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository). 45 | 46 | 3. Edit the `pom.xml` file, fixing all the lines labeled `FIXME`. 47 | 48 | 4. Remove the `GaussFiltering.java` file and add your own `.java` files 49 | to `src/main/java//` (if you need supporting files such as icons 50 | in the resulting `.jar` file, put them into `src/main/resources/`) 51 | 52 | 5. Replace the contents of `README.md` with information about your project. 53 | 54 | 6. Make your initial 55 | [commit](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/making-changes-in-a-branch/committing-and-reviewing-changes-to-your-project) and 56 | [push the results](https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository)! 57 | 58 | ### Eclipse: To ensure that Maven copies the command to your ImageJ2 folder 59 | 60 | 1. Go to _Run Configurations..._ 61 | 2. Choose _Maven Build_ 62 | 3. Add the following parameter: 63 | - name: `scijava.app.directory` 64 | - value: `/path/to/ImageJ2.app/` 65 | 66 | This ensures that the final `.jar` file will also be copied 67 | into your ImageJ2 folder everytime you run the Maven build. 68 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | 9 | org.scijava 10 | pom-scijava 11 | 31.1.0 12 | 13 | 14 | 15 | com.mycompany 16 | GaussFiltering 17 | 0.1.0-SNAPSHOT 18 | 19 | Gauss Filtering 20 | A Maven project implementing an ImageJ command. 21 | https://mycompany.com/imagej/gauss-filtering/ 22 | 2017 23 | 24 | My Company 25 | https://mycompany.com/ 26 | 27 | 28 | 29 | CC0 30 | https://creativecommons.org/publicdomain/zero/1.0/ 31 | repo 32 | 33 | 34 | 35 | 36 | 37 | 38 | octocat 39 | Noma Onomatopoeia 40 | https://mycompany.com/people/noma-onomatopoeia 41 | 42 | founder 43 | lead 44 | developer 45 | debugger 46 | reviewer 47 | support 48 | maintainer 49 | 50 | 51 | 52 | 53 | 54 | None 55 | 56 | 57 | 58 | 59 | 60 | Image.sc Forum 61 | https://forum.image.sc/tag/imagej 62 | 63 | 64 | 65 | 66 | scm:git:https://github.com/imagej/example-imagej2-command 67 | scm:git:git@github.com:imagej/example-imagej2-command 68 | HEAD 69 | https://github.com/imagej/example-imagej2-command 70 | 71 | 72 | GitHub Issues 73 | https://github.com/imagej/example-imagej2-command/issues 74 | 75 | 76 | None 77 | 78 | 79 | 80 | com.mycompany.imagej 81 | com.mycompany.imagej.GaussFiltering 82 | cc0 83 | My Company, Inc. 84 | 85 | 86 | 87 | 88 | scijava.public 89 | https://maven.scijava.org/content/groups/public 90 | 91 | 92 | 93 | 94 | 95 | net.imagej 96 | imagej 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /src/main/java/com/mycompany/imagej/GaussFiltering.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To the extent possible under law, the ImageJ developers have waived 3 | * all copyright and related or neighboring rights to this tutorial code. 4 | * 5 | * See the CC0 1.0 Universal license for details: 6 | * http://creativecommons.org/publicdomain/zero/1.0/ 7 | */ 8 | 9 | package com.mycompany.imagej; 10 | 11 | import net.imagej.Dataset; 12 | import net.imagej.ImageJ; 13 | import net.imagej.ops.OpService; 14 | import net.imglib2.RandomAccessibleInterval; 15 | import net.imglib2.img.Img; 16 | import net.imglib2.type.numeric.RealType; 17 | import org.scijava.command.Command; 18 | import org.scijava.plugin.Parameter; 19 | import org.scijava.plugin.Plugin; 20 | import org.scijava.ui.UIService; 21 | 22 | import java.io.File; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** 27 | * This example illustrates how to create an ImageJ {@link Command} plugin. 28 | *

29 | * The code here is a simple Gaussian blur using ImageJ Ops. 30 | *

31 | *

32 | * You should replace the parameter fields with your own inputs and outputs, 33 | * and replace the {@link run} method implementation with your own logic. 34 | *

35 | */ 36 | @Plugin(type = Command.class, menuPath = "Plugins>Gauss Filtering") 37 | public class GaussFiltering> implements Command { 38 | // 39 | // Feel free to add more parameters here... 40 | // 41 | 42 | @Parameter 43 | private Dataset currentData; 44 | 45 | @Parameter 46 | private UIService uiService; 47 | 48 | @Parameter 49 | private OpService opService; 50 | 51 | @Override 52 | public void run() { 53 | final Img image = (Img)currentData.getImgPlus(); 54 | 55 | // 56 | // Enter image processing code here ... 57 | // The following is just a Gauss filtering example 58 | // 59 | final double[] sigmas = {1.0, 3.0, 5.0}; 60 | 61 | List> results = new ArrayList<>(); 62 | 63 | for (double sigma : sigmas) { 64 | results.add(opService.filter().gauss(image, sigma)); 65 | } 66 | 67 | // display result 68 | for (RandomAccessibleInterval elem : results) { 69 | uiService.show(elem); 70 | } 71 | } 72 | 73 | /** 74 | * This main function serves for development purposes. 75 | * It allows you to run the plugin immediately out of 76 | * your integrated development environment (IDE). 77 | * 78 | * @param args whatever, it's ignored 79 | * @throws Exception 80 | */ 81 | public static void main(final String... args) throws Exception { 82 | // create the ImageJ application context with all available services 83 | final ImageJ ij = new ImageJ(); 84 | ij.ui().showUI(); 85 | 86 | // ask the user for a file to open 87 | final File file = ij.ui().chooseFile(null, "open"); 88 | 89 | if (file != null) { 90 | // load the dataset 91 | final Dataset dataset = ij.scifio().datasetIO().open(file.getPath()); 92 | 93 | // show the image 94 | ij.ui().show(dataset); 95 | 96 | // invoke the plugin 97 | ij.command().run(GaussFiltering.class, true); 98 | } 99 | } 100 | 101 | } 102 | --------------------------------------------------------------------------------