Making a custom ImageWindow

Hello!
I’ve been working on a plugin and I’m not sure how to proceed from here.

I’ve generated a false colour image, an ImagePlus, from a stack of images. I’ve been using this false colour image to allow the user to select regions-of-interest for the stack. I’ve been displaying it using UIService.show().

This however opens it up to the problem of the user attempting to transform the false colour image, which breaks how the region-of-interest translates to the image stack.

I’ve been trying to display this false colour image by extending ij.gui.ImageWindow. Where I can restrict the types of transformations to the JButtons I want to implement and record the transformations made. This would allow the user to adjust the view on the preview image while informing the plugin.

I’m honestly not sure where to start. I’ve not been able to get ImageJ to display this extended ImageWindow. It’s just an empty class extending ImageWindow right now. I’ve used WindowManager and UIService to display it so far.

I’ve not been able to find an example from among Fiji’s plugins so far and I would dearly appreciate it if I could get a reference to a plugin’s source code I could learn from.

Failing that, a nudge in the right direction would be much appreciated.

Thank You,
Reuben

Note that ij.gui.ImageWindow and ij.WindowManager are ImageJ 1.x classes, whereas org.scijava.ui.UIService is a service provided by SciJava and part of ImageJ2.

While all of these work together in Fiji, as a developer you should be aware of the differences.

The development of ImageJ2 and SciJava aims at strictly separating the concerns of functionality and user interface, allowing to create plugins that run in headless environments, e.g. on a cluster, or integrated in other frameworks such as KNIME.

The UI of Fiji however is still based on ImageJ 1.x, which is integrated by the imagej-legacy layer.


That said, I’d suggest that you try to implement all the actual functionality of your plugin as SciJava Commands (see example-imagej-command). If you need some specific UI on top of that, you can indeed use ImageWindow or StackWindow and stick to IJ1 classes, but separating the UI from the commands and keeping them modular will help in maintenance and re-usability of your work.

I recommend taking a look at @iarganda’s Trainable Segmentation plugin, in particular its inner class CustomWindow:

… or Morphological Segmentation (part of MorphoLibJ):

2 Likes

Thank you! This helps immensely!

but separating the UI from the commands and keeping them modular will help in maintenance and re-usability of your work.

I’ve been using a finite state machine as a dispatching thread to the UI. I’ve not been doing any work on the dataset from within the UI classes but passing user input to the dispatching thread and working on the data by calling functions from there. Would this suffice?

That said, I’d suggest that you try to implement all the actual functionality of your plugin as SciJava Command s (see example-imagej-command ).

Thankfully, I’ve done this bit already. The command puts the dispatching thread in its initial state. Thank you for the help!

Note that ij.gui.ImageWindow and ij.WindowManager are ImageJ 1.x classes, whereas org.scijava.ui.UIService is a service provided by SciJava and part of ImageJ2.

While all of these work together in Fiji, as a developer you should be aware of the differences.

The development of ImageJ2 and SciJava aims at strictly separating the concerns of functionality and user interface, allowing to create plugins that run in headless environments, e.g. on a cluster, or integrated in other frameworks such as KNIME.

The UI of Fiji however is still based on ImageJ 1.x, which is integrated by the imagej-legacy layer.

Thank you, I’ll research more into UIService.

Thanks again for your help!

Hey @Reuben_Ganesan
I by accident stumbled upon this thread, and I was struggling with the same issue.

One interesting solution to this problem would be to use BigDataViewer library. There, you can actually get the image viewer panel using the Handler, and essentially put it into a JFrame of your choice, and
event handling is very easy, plus access to overlays.
See https://github.com/bigdataviewer/bigdataviewer-vistools/tree/master/src/test/java/bdv/util.

Dear @imagejan,
Is there a way to do the same task with the UIService operations? I’ve been asking around, and apparently no one exactly knows how to handle events for this viewer.

1 Like