spatialdata icon indicating copy to clipboard operation
spatialdata copied to clipboard

`_get_unique_label_values_as_index()` should be included as a case of `get_values()`

Open LucaMarconato opened this issue 1 year ago • 1 comments

get_values() should have an argument, like index: bool=False, that should return the index when index=True.

Returning the index of shapes and points is straighforward, but currently for returning the index of single-scale and multi-scale labels we use the private function _get_unique_label_values_as_index(). get_values() would make the access more ergonomic.

  • [ ] when implemented, update the tables notebook removing the reference to the private function.

LucaMarconato avatar Mar 28 '24 19:03 LucaMarconato

In this context, it should also be decided whether "background" (label 0) is considered the absence of instances or a normal image segment that can be annotated.

I noticed that _get_unique_label_values_as_index() in the notebook returns label 0.

We use a function unique_labels that returns unique labels excluding 0.
def unique_labels(label_image: Union[np.ndarray, da.Array) -> np.ndarray:
    """
    Extracts the non-zero labels from a labels image.

    Args:
        label_image: A two-dimensional integer array where values of 0 correspond to the background
            (no label).

    Returns:
        A one-dimensional sorted array containing all non-zero labels. An empty array if there are
        no labels.
    """
    # Explicitly converting to an array for Dask support.
    # Dask arrays require computation before the subsequent indexing operation.
    labels = np.asarray(np.unique(label_image))
    if labels.size > 0 and labels[0] == 0:
        return labels[1:]
    else:
        return labels

aeisenbarth avatar May 25 '24 14:05 aeisenbarth