I’m trying to get a labeling image from just a single slice of a stack, using ImageJ2 (i.e.
With the following (Groovy) script (and the new
ImgLabeling conversion in
imagej-common-0.33.0), when trying e.g. on the Bat Cochlea Volume sample image:
#@ Dataset inputStack #@ ConvertService cs #@ OpService ops #@ UIService ui import net.imglib2.roi.labeling.ImgLabeling slice = ops.transform().hyperSliceView(inputStack, 2, 10) //ui.show(slice) labeling = cs.convert(slice, ImgLabeling.class) //ui.show(labeling.getIndexImg()) println labeling.getMapping().getLabels()
I get an empty set (
) when trying to convert just a slice, whereas everything works as expected (
) when I convert the entire stack:
labeling = cs.convert(inputStack, ImgLabeling.class)
When showing the index image, I do see a correct one (with continuous labels starting at 1) for the entire stack, but just a copy of the slice (with index at 255) for the “converted” single slice.
My questions to the ImgLib2 experts:
- Is there something wrong in my implementation of the conversion? (See imagej-common changes)
- Is there something wrong in how I use ImageJ Ops to get the slice (view)? Should I make a copy first?
- Is there something wrong in my script?
Thanks all for your help.