dask-image icon indicating copy to clipboard operation
dask-image copied to clipboard

could ndmeasure functions with index parameters take arrays?

Open chrisroat opened this issue 5 years ago • 1 comments

  • dask-image version: 0.2.0
  • Python version: 3.6
  • Operating System: Ubuntu 18.04

Description

I often want to label an array using dask_image, and then measure something about all the labels (except background). The measurement functions take a parameter index which is a list of labels, but the number of labels found is returned as a (delayed) dask array.

I understand the number of labels is global -- am I out of luck in avoiding nlabels.compute() below? At the very least, it would be nice to avoid directly doing that, even if it is done under the hood during execution.

Even nicer would be the functionality to just specify "all labels" or "all labels except 0", which I think are common cases. Does that seem reasonable?

What I Did

arr = da.from_array([
    [0, 0, 0, 1, 1],
    [0, 0, 0, 0, 0],
    [1, 1, 0, 1, 1],
    [1, 1, 0, 1, 1],
])
labels, nlabels = ndmeasure.label(arr)
ndmeasure.center_of_mass(arr, labels, range(1, nlabels+1))

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-38-174ac9f97d82> in <module>
      6 ])
      7 labels, nlabels = ndmeasure.label(arr)
----> 8 ndmeasure.center_of_mass(arr, labels, range(1, nlabels+1))

TypeError: 'Array' object cannot be interpreted as an integer

chrisroat avatar Dec 06 '19 18:12 chrisroat

This isn't something that works now, but I would like it if we could handle more of this "under the hood". There's a previous discussion here https://github.com/dask/dask-image/issues/116 (jump in if you like). I haven't had time to do much more with it, so it's currently open.

GenevieveBuckley avatar Dec 08 '19 22:12 GenevieveBuckley