This first exercise is to introduce the ImageJ API in Java.
- Open
SimpleFloodFillingclass
The first task is to replace the TODO 1 by the right instruction.
- Open an image as
ImagePlusobject - Get the width & height of an
ImagePlusobject
Note 1: To know what are the ImageJ commands, don't forget to use the macro recorder !
Note 2: IntelliJ has nice auto-completion. If you want to access object methods or fields, just type the
objectName.and a list of all the available methods/ fields will be displayed
Note 3: Once you've found the right command, to clean the code, you can delete the TODO line.
- Run the code in order to test it
- If you get the following output image, then it means that your code is working
- Commit the changes you made, in order to save the current code state.
Note: It is a good practice to test the modifications you are added to code regularly. It will help you troubleshoot more easily your code and make sure that you are doing what you are expecting the code to do.
The output image is not very nice to look at ; the display doesn't allow to visualize all the detected blobs. This is due to the Look-Up Table (LUT) that is used on this image.
-
In order to have a better display, change the LUT so that all the blobs can be visualize. Here is an example of a good LUT (you can apply any LUT from the below list)
-
Run the code to test it
-
Commit changes.
The image output by the code is called a label image. It means that each blob has a certain intensity value, different from each other.
The goal of this exercise to convert the label image into a list of ROIs,
in order to work on objects instead of image. In ImageJ, there is a plugin
called Analyze particles that transforms a binary image into a list of
ROIs but this plugin cannot be applied on a label image (because it
is not binary).
Fortunately, you are not the first one having this issue and a solution has already been developed. One solution is to use an extra library called LaRoMe which embeds a plugin called Label2Rois.
In order to include this library to your code, you have to modify the pom.xml file.
- Open the
pom.xml - Add LaRoMe library as dependency in the
pomfile
Hint: You can find the public package information in the
pomfile of the library itself. See https://github.com/BIOP/ijp-LaRoMe/blob/master/pom.xml#L12
- Refresh maven, to include the new dependency to your code
- Uncomment lines 50-51 in
SimpleFloodFilling; those lines are calling Label2Rois plugin - Do not forget to import the class Label2Rois
Hint: If you pass your mouse over the red underlined class, a popup appears proposing you to import the corresponding class.
- Run the code to test it
- Commit changes.
The code works now as expected but it is not ready to be a Fiji plugin.
In order to make it a plugin, we need to add a few commands that are illustrated in SimpleFloodFillingCommand
@Plugin: on line 22, this parameter tells Fiji that this class has to be considered as a plugin, and this plugin can be found in the Fiji menumenuPath.@Override public void run(): this method is a mandatory method, inherited from the@Plugincommand. It is the method called when you click onPlugin -> ...in Fiji.
public static voic main: the main method is still used here, to be able to run the code from IntelliJ but its content is now completely different. The main is now used to open an ImageJ GUI, where you can find your plugin to run.
- Uncomment lines 65-66
- Do not forget to import the class Label2Rois
- Run the code to test it
- Commit changes.
Note: if you encounter some weird issue at code startup, mainly described as
Java.lang.IllegalArgumentException: Invalid service: net.imagej.legacy.LegacyService, try to launch the plugin using theSimpleIJLaunchJava class.