dask / dask/dask-image

could ndmeasure functions with index parameters take arrays?

Open
#132 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
226
Forks
56
PR merge metrics
No merged PRs in 30d

Description

* 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)
in
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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.