Call a LabelRegions region and remove it

Tags: #<Tag:0x00007fb87e0cbb40> #<Tag:0x00007fb87e0cb5f0> #<Tag:0x00007fb87e0cb438>


Dear all,

I have a question regarding removing specific components found by connected component analysis (cca).

I have a labeled image after running cca as follows:

ImgLabeling<T,UnsignedByteType> labeledImage = ops.labeling().cca((RandomAccessibleInterval<T>) inputImage, ConnectedComponents.StructuringElement.EIGHT_CONNECTED);

After that, I can iterate components through a for loop like this:

LabelRegions<?> regions = new LabelRegions<>(labeledImage);
for (LabelRegion<?> region : regions) {
        DoubleType size = ops.geom().size(region);

Now I am trying to;
1) Call a specific region (let’s say regions[i]),
2) And remove this region from labeledImage or fill it with zeros.

However, I could not find a way to call regions[i] and remove it from the labeledImage.
Can anyone suggest a way to achieve these?

Any idea would be very helpful!


Hey @ImageAnalyser,

(cool nickname btw) to answer your first question, there is a method for this:

region = regions.getLabelRegion(i); 

The second part is a bit more tricky. I’m afraid removing a region is not supported yet, but @tpietzsch may correct me here. I did something like that (the code is not open unfortunately) at some point where I collected all regions I wanted to keep in an ArrayList. After the list was filled, I went through a new image stack and filled all pixels with the corresponding index of the region in the list. This may be a bit slow but it does the thing. However, the LabelRegion API allows overlapping regions, while my approach does not.

I hope that helps.



Hi Robert,

Thank you for your helpful ideas. When I try to use the following method,

I get the following error: The method getLabelRegion(capture#6-of ?) in the type LabelRegions<capture#6-of ?> is not applicable for the arguments (int).

I couldn’t find a way to solve this issue. Therefore I can’t try to collect the regions in an ArrayList.
How can I solve this issue?



Hi @ImageAnalyser,

that brings us to Java generics. I work with regions, where the regions are labelled with integers (Region 1, Region 2,. …). You apparently don’t. According your first code snipped

Your label type is UnsignedByteType. I know it may sound stupid, but could you try casting the integer index to a byte?