arboretum/utils.py
def _localize_process(data: tuple,
                      is_binary: bool = True,
                      use_labels: bool = False) -> np.ndarray:

    # image: np.ndarray, frame: int) -> np.ndarray:
    """ worker process for localizing and labelling objects

    volumetric data is usually of the format: t, z, x, y

    Returns:
        combined data in form of nx5 array (t, x, y, z, label) adding a
        z-dimension of uniform zero, if one doesn't exist.
    """

    if use_labels: assert is_binary

    image, frame = data
    assert image.dtype in (np.uint8, np.uint16)

    if is_binary:
        labeled, n = measurements.label(image.astype(np.bool))
        idx = list(range(1, n+1))
    else:
        labeled = image
        idx = [p for p in np.unique(labeled) if p>0]

    # calculate the centroids

    centroids = np.array(measurements.center_of_mass(image,
                                                     labels=labeled,
                                                     index=idx))

    # if we're dealing with volumetric data, reorder so that z is last
    if image.ndim == 3:
        centroids = np.roll(centroids, -1)

    localizations = np.zeros((centroids.shape[0], 5), dtype=np.uint16)
    localizations[:,0] = frame # time
    localizations[:,1:centroids.shape[1]+1] = centroids
    localizations[:,-1] = 0 #labels-1 #-1 because we use a label of zero for states

    # if we're not using labels from the segmentation, return here
    if not use_labels:
        return localizations

    # get the labels from the image data
    labels = np.array(measurements.maximum(image, labels=labeled, index=idx))
    localizations[:,-1] = labels-1 #-1 because we use a label of zero for states

    return localizations
 worker process for localizing and labelling objects

    volumetric data is usually of the format: t, z, x, y

    Returns:
        combined data in form of nx5 array (t, x, y, z, label) adding a
        z-dimension of uniform zero, if one doesn't exist.
    
worker process for localizing and labelling objects
volumetric data is usually of the format: t, z, x, y
worker process for localizing and labelling objects volumetric data is usually of the format : t z x y
def _localize_process(data: tuple,
                      is_binary: bool = True,
                      use_labels: bool = False) -> np.ndarray:
    if use_labels: assert is_binary
    image, frame = data
    assert image.dtype in (np.uint8, np.uint16)
    if is_binary:
        labeled, n = measurements.label(image.astype(np.bool))
        idx = list(range(1, n+1))
    else:
        labeled = image
        idx = [p for p in np.unique(labeled) if p>0]
    centroids = np.array(measurements.center_of_mass(image,
                                                     labels=labeled,
                                                     index=idx))
    if image.ndim == 3:
        centroids = np.roll(centroids, -1)
    localizations = np.zeros((centroids.shape[0], 5), dtype=np.uint16)
    localizations[:,0] = frame 
    localizations[:,1:centroids.shape[1]+1] = centroids
    localizations[:,-1] = 0 
    if not use_labels:
        return localizations
    labels = np.array(measurements.maximum(image, labels=labeled, index=idx))
    localizations[:,-1] = labels-1 
    return localizations
def _localize_process ( data : tuple , is_binary : bool = True , use_labels : bool = False ) -> np . ndarray : if use_labels : assert is_binary image , frame = data assert image . dtype in ( np . uint8 , np . uint16 ) if is_binary : labeled , n = measurements . label ( image . astype ( np . bool ) ) idx = list ( range ( 1 , n + 1 ) ) else : labeled = image idx = [ p for p in np . unique ( labeled ) if p > 0 ] centroids = np . array ( measurements . center_of_mass ( image , labels = labeled , index = idx ) ) if image . ndim == 3 : centroids = np . roll ( centroids , - 1 ) localizations = np . zeros ( ( centroids . shape [ 0 ] , 5 ) , dtype = np . uint16 ) localizations [ : , 0 ] = frame localizations [ : , 1 : centroids . shape [ 1 ] + 1 ] = centroids localizations [ : , - 1 ] = 0 if not use_labels : return localizations labels = np . array ( measurements . maximum ( image , labels = labeled , index = idx ) ) localizations [ : , - 1 ] = labels - 1 return localizations
worker process for localizing and labelling objects
volumetric data is usually of the format: t, z, x, y
worker process for localizing and labelling objects volumetric data is usually of the format : t z x y
# image: np.ndarray, frame: int) -> np.ndarray: """ worker process for localizing and labelling objects

    volumetric data is usually of the format: t, z, x, y

    Returns:
        combined data in form of nx5 array (t, x, y, z, label) adding a
        z-dimension of uniform zero, if one doesn't exist.
    """ # calculate the centroids # if we're dealing with volumetric data, reorder so that z is last # time #labels-1 #-1 because we use a label of zero for states # if we're not using labels from the segmentation, return here # get the labels from the image data #-1 because we use a label of zero for states
combined data in form of nx5 array (t, x, y, z, label) adding a
z-dimension of uniform zero, if one doesn't exist.
combined data in form of nx5 array ( t x y z label ) adding a z - dimension of uniform zero if one doesn ' t exist .
data
tuple
is_binary
bool
use_labels
bool