imglib / imglib2-roi

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

Utility methods to remap labels of labelings #54

Closed imagejan closed 4 years ago

imagejan commented 4 years ago

I was considering adding a utility method to transform ImgLabelings by mapping the existing labels T to some new labels U, given a Function<T,U>.

ImgLabeling<U,I> remapLabels( ImgLabeling<T,I> labeling, Function<T,U> function )

This would be similar to what the Label Transformer node in knime-ip/knip is currently doing.

Two questions:

tpietzsch commented 4 years ago
  • Is there any interest to have this as a static method in net.imglib2.roi.labeling.Labelings?

It would be cool to have this, absolutely!

  • Is this any better than simply creating a new labeling and iterating over input and output with two Cursors?

It would be definitely much faster.

The only potential problem is if function is not injective. I'm not sure what would happen if you have function = {1->a, 2->a, 3->b, ... } and now the previously distinct label sets {1}, {2}, and {1,2} all become {a}. But if it is a problem, we could just point out in the javadoc that is is not allowed.