예제 #1
0
def derts2blobs(dert__, verbose=False, render=False, use_c=False):

    if verbose:
        start_time = time()

    if use_c:
        dert__ = dert__[0], np.empty(0), np.empty(0), *dert__[1:], np.empty(0)
        frame, idmap, adj_pairs = wrapped_flood_fill(dert__)
    else:
        blob_, idmap, adj_pairs = flood_fill(dert__,
                                             sign__=dert__[3] > 0,  # sign of deviation of gradient
                                             # g__ was not signed, we used dy__ sign instead
                                             verbose=verbose)
        I = Dy = Dx = G = M = 0
        for blob in blob_:
            I += blob.I
            Dy += blob.Dy
            Dx += blob.Dx
            G += blob.G
            M += blob.M
        frame = FrameOfBlobs(I=I, Dy=Dy, Dx=Dx, G=G, M=M, blob_=blob_, dert__=dert__)

    assign_adjacents(adj_pairs)

    if verbose:
        print(f"{len(frame.blob_)} blobs formed in {time() - start_time} seconds")

    if render:
        visualize_blobs(idmap, frame.blob_)

    return frame
예제 #2
0
def cluster_derts(dert__, mask, Ave, fcr, fca, verbose=False, **kwargs):

    if fca:
        crit__ = Ave - dert__[3]  # temporary crit
    elif fcr:  # comp_r output;  form clustering criterion:
        crit__ = Ave - dert__[3]  # eval by -g, accum in rng
    else:
        crit__ = Ave - dert__[3]  # eval by -g, accum in rng

    if kwargs.get('use_c'):
        raise NotImplementedError
        (_, _, _, blob_, _), idmap, adj_pairs = flood_fill()
    else:
        blob_, idmap, adj_pairs = flood_fill(dert__,
                                             sign__=crit__ > 0,
                                             verbose=verbose,
                                             mask=mask,
                                             blob_cls=CDeepBlob,
                                             accum_func=accum_blob_Dert)

    assign_adjacents(adj_pairs, CDeepBlob)
    if kwargs.get('render', False):
        visualize_blobs(idmap,
                        blob_,
                        winname=f"Deep blobs (fcr = {fcr}, fig = {fig})")

    return blob_
예제 #3
0
def cluster_derts(dert__, mask, Ave, fcr, fig, verbose=False, **kwargs):

    if fcr:  # comp_r output;  form clustering criterion:
        if fig:
            crit__ = dert__[0] + dert__[
                6] - Ave  # eval by i + m, accum in rng; dert__[:,:,0] if not transposed
        else:
            crit__ = Ave - dert__[3]  # eval by -g, accum in rng
    else:  # comp_g output
        crit__ = dert__[
            6] - Ave  # comp_g output eval by m, or clustering is always by m?
    if kwargs.get('use_c'):
        raise NotImplementedError
        (_, _, _, blob_, _), idmap, adj_pairs = flood_fill()
    else:
        blob_, idmap, adj_pairs = flood_fill(dert__,
                                             sign__=crit__ > 0,
                                             verbose=verbose,
                                             mask=mask,
                                             blob_cls=CDeepBlob,
                                             accum_func=accum_blob_Dert)

    assign_adjacents(adj_pairs, CDeepBlob)
    if kwargs.get('render', False):
        visualize_blobs(idmap,
                        blob_,
                        winname=f"Deep blobs (fcr = {fcr}, fig = {fig})")

    return blob_
예제 #4
0
def cluster_derts(dert__, crit__, mask, verbose=False, **kwargs):
    # this is function should be folded into flood_fill()
    ''' obsolete define clustering criterion:
    if fia:      # input is from comp_a
        if fca:  # comp_a eval by g / cos(ga)
            crit__ = dert__[3] / np.cos(dert__[7]) - Ave  # combined value, no comp_r: no use for ma?
        else:    # P_blobs eval by g * cos(ga)
            crit__ = dert__[3] * np.cos(dert__[7]) - Ave  # separate from g and ga
    else:        # input is from comp_r
        if fca:  # comp_a eval by g
            crit__ = dert__[3] - Ave
        else:    # comp_r eval by m
            crit__ = dert__[4] - Ave
    '''
    if kwargs.get('use_c'):
        raise NotImplementedError
        (_, _, _, blob_, _), idmap, adj_pairs = flood_fill()
    else:
        blob_, idmap, adj_pairs = flood_fill(dert__,
                                             sign__=crit__ > 0,
                                             verbose=verbose,
                                             mask=mask,
                                             blob_cls=CDeepBlob,
                                             accum_func=accum_blob_Dert)

    assign_adjacents(adj_pairs, CDeepBlob)
    if kwargs.get('render', False):
        visualize_blobs(idmap,
                        blob_,
                        winname=f"Deep blobs (fcr = {fcr}, fia = {fia})")

    return blob_