Further analysis of LabelRegions

imglib2
imagej-ops
Tags: #<Tag:0x00007fd54855fd28> #<Tag:0x00007fd54855f698>

#1

Hi all,

I want to create a labelling of an image, and then analyse the regions of the image with other ops. For example, I’d like to calculate the connectivity of each particle in an image. Following others’ code examples I got this far:

final ImgLabeling<Integer, IntType> labeling = opService.labeling().cca(
	inputImage, ConnectedComponents.StructuringElement.EIGHT_CONNECTED);
uiService.show(labeling.getIndexImg());

final ImgPlus<BitType> bitTypeImgPlus = Common.toBitTypeImgPlus(opService,
	inputImage);
final LabelRegions<Integer> regions = new LabelRegions<>(labeling);
final Set<Integer> labels = regions.getExistingLabels();
labels.forEach(label -> {
	final LabelRegion<Integer> region = regions.getLabelRegion(label);
	final IterableInterval<BitType> sample = Regions.sample(region,
		bitTypeImgPlus);
	final Img<BitType> bitTypeImg = opService.convert().bit(sample);
	final double connectivity = opService.topology()
		.eulerCharacteristic26NFloating(bitTypeImg).get();
	System.out.println("Connectivity " + connectivity);
});

The code crashes at opService.convert() with a

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at net.imagej.ops.thread.chunker.DefaultChunker.run(DefaultChunker.java:104)

I’ve forgotten how to convert/wrap an IterableInterval into a RandomAccessibleInterval. How do I do that?

Furthermore, if I wanted to exclude regions that intersect image edges, how could I go about it?

Best regards,
Richard


#2

Actually, you don’t. You can always convert a RAI to an IterableInterval using e.g. Views.iterable(...) or the corresponding ops().* command. However, the other way round is not as trivial. It’s rather worth investigating why your code crashes. Conversions are usually pixelwise, so this can’t be an OOB in the image?! Maybe you can catch the IndexOutOfBoundsException and debug what’s going on?

There can only be regions which touch the border if you create an ImgLabeling using a CCA and if the resulting ImgLabeling has the same dimensions as the image you want to sample for your measurements (i.e. coordinates have min or max values in one dimension).


#3

The exception happens at net.imglib2.roi.util.iterationcode.IterationCodeListIterator.initNextItcode() at line 108: itcode = itcodesList.get( itcodesListIndex++ ); because itcodesListIndex == itcodesList.size(). We end up here thorugh the DefaultChunker op, that gets called when the convert op is mapped to parellel (net.imagej.ops.map.Maps.map()). My LabelRegions seem OK: I’m testing with the bat_cochlea sample, so there’s one region with the same number of elements as there are foreground voxels in the image. The IterableInterval from Regions.sample is OK too.

I’m sorry, I don’t follow. What I meant was getting from the 1st situation to the 2nd:


that is, how can I exclude from my LabelRegions the particles that are “cropped” in the image, cut off by the bounding box?