cytometer/utils.py
def edge_labels(labels):
    """
    Find which labels touch the borders of the image. The background label (0) will be ignored.

    :param labels: 2D numpy.ndarray with segmentation labels.
    :return:
    edge_labels: numpy.ndarray with list of labels.
    """

    if labels.ndim != 2:
        raise ValueError('labels must be a 2D array')

    # labels that touch the top edge of the image
    edge_labels = np.unique(labels[0, :])

    # labels that touch the left edge
    edge_labels = np.unique(np.concatenate((edge_labels, labels[:, 0].flat)))

    # labels that touch the right edge
    edge_labels = np.unique(np.concatenate((edge_labels, labels[:, -1].flat)))

    # labels that touch the bottom edge
    edge_labels = np.unique(np.concatenate((edge_labels, labels[-1, :].flat)))

    # remove label=0, if present
    edge_labels = np.setdiff1d(edge_labels, 0)

    return edge_labels

    Find which labels touch the borders of the image. The background label (0) will be ignored.

    :param labels: 2D numpy.ndarray with segmentation labels.
    :return:
    edge_labels: numpy.ndarray with list of labels.
    
Find which labels touch the borders of the image. The background label (0) will be ignored.
Find which labels touch the borders of the image . The background label ( 0 ) will be ignored .
def edge_labels(labels):
    if labels.ndim != 2:
        raise ValueError('labels must be a 2D array')
    edge_labels = np.unique(labels[0, :])
    edge_labels = np.unique(np.concatenate((edge_labels, labels[:, 0].flat)))
    edge_labels = np.unique(np.concatenate((edge_labels, labels[:, -1].flat)))
    edge_labels = np.unique(np.concatenate((edge_labels, labels[-1, :].flat)))
    edge_labels = np.setdiff1d(edge_labels, 0)
    return edge_labels
def edge_labels ( labels ) : if labels . ndim != 2 : raise ValueError ( 'labels must be a 2D array' ) edge_labels = np . unique ( labels [ 0 , : ] ) edge_labels = np . unique ( np . concatenate ( ( edge_labels , labels [ : , 0 ] . flat ) ) ) edge_labels = np . unique ( np . concatenate ( ( edge_labels , labels [ : , - 1 ] . flat ) ) ) edge_labels = np . unique ( np . concatenate ( ( edge_labels , labels [ - 1 , : ] . flat ) ) ) edge_labels = np . setdiff1d ( edge_labels , 0 ) return edge_labels
Find which labels touch the borders of the image.
Find which labels touch the borders of the image .
"""
    Find which labels touch the borders of the image. The background label (0) will be ignored.

    :param labels: 2D numpy.ndarray with segmentation labels.
    :return:
    edge_labels: numpy.ndarray with list of labels.
    """ # labels that touch the top edge of the image # labels that touch the left edge # labels that touch the right edge # labels that touch the bottom edge # remove label=0, if present
numpy.ndarray with list of labels.
numpy . ndarray with list of labels .
labels
2D numpy.ndarray with segmentation labels.
2D numpy . ndarray with segmentation labels .