Imagej1 vs Imagej2 Java API cheat sheet?

imagej1
imagej
imagej2

#1

I’m wondering if there is a cheat sheet between ImageJ1 API and ImageJ2 API like this one for R and MATLAB? Either class- or method-based comparisons would help a lot to understand ImageJ2! At the moment, it’s really hard to see the relationship or translate between the two.

To be specific, I’m looking for an ImageJ2 equivalent of ij.IJ.getImage() but could not find it.

It may be worthwhile to have a cheat sheet for a few most frequently used methods.


#2

Hey @kouichi-c-nakamura,

I like the cheat sheet idea! There are many people looking for that I think. Maybe we can create a repository where we collect a list like this? I would also be interested in a cheat sheet for scripting, like comparing IJ1 / IJ2 / groovy scripts…

To answer your specific question: I have not tried it, but there is an ImageDisplayService with a getActiveDataset() function. Maybe that works?


#3

Also, these wiki pages helped me figure out a few things:

  • Plugin writing in IJ1 vs IJ2
  • Scripting in Python/Jython based on IJ1 vs IJ2

#4

I remember that Robert made a cheat sheet for the 2017 Learnathon. It was somewhere on Github, but I cannot find it anymore…

@haesleinhuepf, where do you hide it :wink: ?

Best,

Nicolas


#5

Hey guys,

the internet forgets nothing, here come the slides and the cheatsheet on IJ1-IJ2 transformation:

Btw: there should be no IJ.getImage() in ImageJ2 as far as I understood the concept. The idea is to use #@Img variableName instead and only ask for images at the beginning of each script…

When it comes to retrieving a result from a plugin execution, @ctrueden recently posted a script, where it works like this:

args = [
	"originalImage": image,
	"createProbabilityImage": true,
	"overlayPatches": false,
	"solidPatches": false,
	"borderWidth": 4,
]
m = command.run(MicroscopeImageFocusQualityClassifier.class, true, args).get()
probDataset = m.getOutput("probDataset")

For full details, see here.

Cheers,
Robert


#6

Thank you for the useful link. Is there a reason why we should not have an editable copy of the same list on the ImageJ web site? It would be more accessible.

Btw: there should be no IJ.getImage() in ImageJ2 as far as I understood the concept. The idea is to use #@Img variableName instead and only ask for images at the beginning of each script…

Thanks a lot. Because at the moment, I’m trying to manipulate ImageJ from within MATLAB, the #@Img variableName style is not really an option.


#7

Have you tried this?

Dataset dataset = ij.imageDisplay().getActiveDataset();

#8

I tried net.imagej.display.DefaultImageDisplayService.getActiveDataset() but resulted in an error.

No method 'getActiveDataset' with matching signature found for class 'net.imagej.display.DefaultImageDisplayService'.

#9

The getActiveDataset() method is not a static method. You need an instance of the ImageDisplayService.

On which page of imagej.net would you propose this guide be located?

Also, I am sorry @kouichi-c-nakamura that I have not had time to respond to your ImageJ-MATLAB questions and issues. It is in my backlog to do so later this summer (after June 11). I know that is small comfort but I wanted to at least let you know, and say thank you for your persistence.


#10

ImageDisplayService is interface, so you cannot instanciate it.

An implementing class is DefaultImageDisplayService.

addpath '/Applications/Fiji.app/scripts'
ImageJ

imp = IJ.openImage('http://imagej.nih.gov/ij/images/blobs.gif');
obj = net.imagej.display.DefaultImageDisplayService;
ds = obj.getActiveDataset();
Java exception occurred:
java.lang.NullPointerException
	at net.imagej.display.DefaultImageDisplayService.getActiveImageDisplay(DefaultImageDisplayService.java:109)
	at net.imagej.display.DefaultImageDisplayService.getActiveDataset(DefaultImageDisplayService.java:114)

On which page of imagej.net would you propose this guide be located?

How about somewhere under this page?

Also, I am sorry @kouichi-c-nakamura that I have not had time to respond to your ImageJ-MATLAB questions and issues.

I hope you like my ijmshow. But ideally it’s better to be dealt with by IJM.show() by itself.


#11

You should not instantiate service classes like that. You have to go through the SciJava application container. It has been years since I looked at this code, but I think something like:

imageDisplayService = IJM.context().service(net.imagej.display.ImageDisplayService.class);

#12

Thanks a lot. The following worked successfully! I’ve found that it’s quite difficult to find a relevant example or documentation for ImageJ. I wonder where did you get the idea?

addpath '/Applications/Fiji.app/scripts'
ImageJ
ids = IJM.context().service(net.imagej.display.ImageDisplayService.class);
ds = ids.getActiveDataset();

#13

I had to look in the source code of ImageJ-MATLAB to find that context() method. Sorry it was never documented. The ImageJ-MATLAB project was the start of an ImageJ2-based extensible approach to integrate with MATLAB, but the time investment for the project was limited, and it has not been developed much since 2016, when the primary author left the ImageJ project.

ImageJ2 is fundamentally service driven: you always go through an application context. See this notebook for an overview.


#14

Thanks a lot. This is very helpful.


#15

I made this page. Now asking permission from the writer of the original.


#16

I love it! Together with @maarzt we may update it a bit with newest code snippets on ROIs :slight_smile:

Thanks for your efforts!

Cheers,
Robert