Seeded region growing imglib2

imglib2

#1

@bogovicj @imagejan @hanslovsky @maarzt

Hi All,

I have a TB sized label map image (pixel values being object Ids),
and I need (to write) a function like this:

RandomAccessibleInterval< BitType > extractObject( RandomAccessibleInterval< UnsignedLongType > labelMap, long[] seedPosition )
{
	final RandomAccess< UnsignedLongType > access = labelMap.randomAccess();
	access.setPosition( seedPosition );
	final long objectId = access.get().getIntegerLong();

	// perform seeded region growing extracting all pixels that are
	// (i) connected to seedPosition
	// (ii) and have value objectId
	// ...

	// create a binary image of minimal size containing all found pixels
	// ...

	return smallBinaryRAIofObjectBoundingBoxSize;
}

I was wondering whether such a function exists already?
For example, paintera seems to need such logic as well to show 3D objects, or are you solving this differently?

Otherwise I thought of modifying this: https://github.com/imglib/imglib2-algorithm/blob/master/src/main/java/net/imglib2/algorithm/fill/FloodFill.java#L184
…, which I think cannot use directly, because I do not apriori know the size of the target image. So, I guess I would instead populate a list of coordinates and only in the end construct an image of minimal size from it?!

I guess another idea would be to actually use the existing FloodFill and use as target image a sparse implementation of a BitType RAI?

All help is very much appreciated!


#2

Yes, the FloodFill class that you already discovered should do the trick.

No, Paintera uses 3D marching cubes on a pre-defined set of blocks for any selected labels. The containing blocks have to be pre-computed.

You should be able to use this flood-fill method. Create a DiskCachedCellImg that is as big as your input image and wrap it into a RandomAccessibleInterval with a RandomAccess that keeps track of the bounding box that it has touched. That should be all you need (it is probably a good idea to extend input/output with appropriate values). Feel free to copy/modify that bounding box tracking RAI as you need.

Yes that should work. I do not know if that would be more efficient than the disk cached cell img option.


#3

Great! I’ll try this! The bounding box tracking is exactly what I need in order to later use Views.interval() to crop out the relevant part.


#4

I got something working :slight_smile:
If you have a few seconds to check whether this could still be improved let me know: https://github.com/tischi/bdv-utils/blob/master/src/main/java/de/embl/cba/bdv/utils/algorithms/RegionExtractor.java#L24
But anyway: @hanslovsky thanks a lot!!