imglib / imglib2-roi

Regions of interest (ROIs) and labelings for ImgLib2
Other
8 stars 8 forks source link

Sparse bitmask #44

Open tpietzsch opened 5 years ago

tpietzsch commented 5 years ago

SparseBitmask is a RandomAccessible<BoolType> based on nTree (quadtree, octree, ...) with little bitmasks (basically ArrayImg<BitType>) in the leafs. It's a RandomAccessible (not Interval). The tree grows on demand, just set pixels wherever...

There are efficient algorithms for

These are provided through a (read-only) view as an IterableRegion.

Some usage examples are in src/test/.

sparsetree

I'm happy with the underlying tree and bitmask stuff (SparseBitmaskNTree, Tree, GrowableTree). However, packaging as a RandomAccessible in SparseBitmask required some trade-offs that are not so clear and depend on use case. I would be happy about some input...

In particular, read/write of pixels is protected by a ReentrantReadWriteLock that is acquired per pixel access. It would be nice to have this more coarse-grained, but I don't know how.

Also, SparseBitmask.region() provides IterableRegion view of the current state, and will throw ConcurrentModificationException when the bitmask is modified. There are some minor trade-offs there as well, but read/write locking is the major problem.

maarzt commented 5 years ago

@tpietzsch I made some quick changes.

  1. Bitmask can be a separate class. That should make the class Tree more readable.
  2. There's a bug with the SpareIterable.region().cursor(), if there one bit set, it iterates over that pixel twice? So there probably a small bug in hasNext.
tpietzsch commented 5 years ago

@maarzt I fixed the bug. Thanks for noticing!

maarzt commented 5 years ago

Bitmask is probably not a got term to refer to a black/white image. Mask or Bitmap are preferable. Bitmask is rather one dimensional. https://en.wikipedia.org/wiki/Bitmap https://en.wikipedia.org/wiki/Mask

imagesc-bot commented 2 years ago

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/imglib2-imaris-bridge-sharing-cached-images-between-imaris-and-fiji/57772/11