Seeded region growing imglib2



@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:
…, 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!


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.


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.


I got something working :slight_smile:
If you have a few seconds to check whether this could still be improved let me know:
But anyway: @hanslovsky thanks a lot!!