Ejemplo n.º 1
0
def oversegment_aff(aff_3d):
    # Thresholds from Zletaski 2009, p. 19
    """
    T_h = 0.98
    T_l = 0.2
    T_e = 0.1
    T_s = 25
    """

    # Thresholds from Aleks's code.
    T_h = 0.99
    T_l = 0.3
    T_s = 25

    if aff_3d.dtype == formats.WEIGHT_DTYPE_UINT:
        T_h = int(T_h * formats.WEIGHT_MAX_UINT)
        T_l = int(T_l * formats.WEIGHT_MAX_UINT)
        T_e = int(T_e * formats.WEIGHT_MAX_UINT)

    # Set each vertex's weight to the max of its adjacent edges
    affv_3d = formats.aff2affv(aff_3d)

    labels_3d = np.zeros(aff_3d.shape[:-1], dtype=formats.LABELS_DTYPE)
    n_labels = 0
    sizes = {}

    # Watershed with edges >= T_h merged, and edges < T_l not considered
    n_labels = connected_components(aff_3d, affv_3d, T_h, labels_3d, n_labels, sizes)
    # We are allowed to apply watershed with some pixels already labeled
    # and without a quick-union structure because, due to the
    # connected_components algo, those labels always contain mins.
    n_labels = watershed(aff_3d, affv_3d, T_l, labels_3d, n_labels, sizes)

    # Create the region graph, and list their edges in decreasing order
    # Ignore unlabeled vertices, since they are "single-vertex segments" and
    # I think they'll be unlikely to reach size > T_s even after the next step.
#    region_graph = get_region_graph(aff_3d, labels_3d, n_labels)

    # For all edges with affinity >= T_e, merge if any segment has size < T_s.
#    n_labels = merge_segments(aff_3d, region_graph, labels_3d, n_labels, sizes, T_s)

    return labels_3d, n_labels
Ejemplo n.º 2
0
def oversegment_aff(aff_3d):
    # Set each vertex's weight to the max of its adjacent edges
    affv_3d = formats.aff2affv(aff_3d)

    labels_3d = np.zeros(aff_3d.shape[:-1], dtype=formats.LABELS_DTYPE)
    n_labels = 0
    aff_dtype = aff_3d.dtype

    for t_cc, t_ws in ((.9,.8),):# (.8,.7), (.7,.6), (.6,.2)):
        if aff_dtype == formats.WEIGHT_DTYPE_UINT:
            t_cc = int(t_cc * formats.WEIGHT_MAX_UINT)
            t_ws = int(t_ws * formats.WEIGHT_MAX_UINT)

        n_labels = connected_components(aff_3d, affv_3d, t_cc, labels_3d, n_labels)

        # We are allowed to apply watershed with some pixels already labeled
        # and without a quick-union structure because, due to the
        # connected_components algo, those labels always contain mins.
        n_labels = watershed(aff_3d, affv_3d, t_ws, labels_3d, n_labels)

    return labels_3d, n_labels