Displaying and using and any Object in a Scijava/FIJI Command

Dear all,

When running an IJ2 command, if I get it right, output objects which cannot be displayed are discarded. Thus FIJI keeps images, tables, and a few other things in memory and accessible for Commands, put otherwise objects are discarded. However there are many types of Object which could benefit from being kept in memory and reused. It would be useful for instance, to keep the result of a registration (RealTransform, AffineTransform, YourPerfectTransform), or image display settings parameters, or whatever object your particular use case need, like a :bird:

The usual workaround to deal with this is to write a file to store these objects, and then reopen the file to retrieve them. I think it would be nice to modify the behaviour of FIJI in order to allow for a more direct and convenient way of using such objects.

The problem in the default behaviour of how a Command deals with a :bird: object consists of two parts:

  • The object is discarded, even when declared as @Parameter(type = ItemIO.OUTPUT)
  • FIJI does not know how to display it

@maarzt came up with a possible solution that addresses these two points (see this repo (https://github.com/maarzt/example-imagej-display)). In practice, being able to use and display a :bird: in a a Command would require:

The example repo also shows how to update the display when the bird is renamed and how to retrieve the scijava context (https://github.com/maarzt/example-imagej-display/tree/master/src/main/java/com/mycompany/imagej).

There’s a common essential class EasySwingDisplayViewer<T> , which enables all of this. Currently it is located in the example repository, but it would be nice to move it somewhere into scijava-ui-swing repo.

Best,

Nicolas

PS : There’s a related question which is how to use BigDataViewer windows with FIJI Commands, see forum post here (https://forum.image.sc/t/getting-bigdataviewer-instance-in-an-imagej-command).

ping @maarzt, @ctrueden, @imagejan, @frauzufall

3 Likes

@NicoKiaru Do you actually want these :bird: objects to be displayed in the UI? Or just remembered by, and made accessible from, some service somewhere?

If you want them to be displayed, then I agree that implementing a Display and DisplayViewer for them makes sense.

If you just want them to be remembered, then I would not (ab)use the Display framework. Rather, you can write a PostprocessorPlugin that recognizes when a :bird: output happens, and informs the BirdService about it. Or even just publishes an event via the EventService, so that any event handling code out there can react to the new :bird:.

3 Likes

It’s usually very useful for the user to know that such objects exist… Displaying them makes the user aware of their presence, and closing the window is actually a good way to get rid of the objects from the ObjectService.

For instance imagine a RealTransform object obtained after a long registration computation. One may want to apply such transform on different images, or reuse it to concatenate it with another transform. Without any display, it’s hard to guess that such object exist.

I’ve made a pull request that’s adding the EasySwingDisplayViewer ‘helper’ class in the scijava-ui-swing repository:

Is that the way to go ?

Happy to discuss it further, it’s definitely something I’ve needed for a long time.

4 Likes

Thanks a lot, @NicoKiaru. I will try to review it within the next few days… please ping me again if I am too slow.

1 Like