Analyze the current slice of an ImgPlus in ImageJ2


I just noticed that when using an ImagePlus from IJ1 and you get the number of pixels, the current slice from the stack is automatically chosen to be analyzed. But with ImgPlus from IJ2, when getting its size(), it returns the sum of pixels of all the images in the stack. Same happens when analyzing the histogram through code.
I know you can get a specific slice through Views.hyperSlice(), but how would you achieve getting the current slice the user is working on? Also out of curiosity, what was the reason for this change?

Thank you


Hi @Rody,

Yup, IJ1 is very “2d-oriented”, and IJ2 (being based on imglib2) is N-d from the start.

Short answer, I don’t know, but I think the way to do this is with:

#@ ImageDisplayService display


// or maybe

but neither gives me the output I expect.

I’ve had weird experiences in the past; maybe this is related?

I haven’t contributed to IJ2, but one thing I like about it is the separation between how the image is displayed from how the image is stored.



I added a note to the issue tracking this:

But I’m afraid there’s currently no-one actively working on solving these issues, mostly due to time constraints and higher priorities, I believe.