Exemplo n.º 1
0
def image_to_blobs(
    image
):  # root function, postfix '_' denotes array, prefix '_' denotes higher- vs lower-line variable

    dert__ = comp_pixel(
        image)  # comparison of central pixel to rim pixels in 3x3 kernel
    frame = dict(rng=1,
                 dert__=dert__,
                 mask=None,
                 I=0,
                 G=0,
                 Dy=0,
                 Dx=0,
                 blob_=[])
    stack_ = deque()  # buffer of running stacks of Ps
    height, width = image.shape

    for y in range(height - kwidth + 1):  # first and last row are discarded
        P_ = deque(form_P_(dert__[:, y].T))  # horizontal clustering
        P_ = scan_P_(
            P_, stack_, frame
        )  # vertical clustering, adds up_forks per P and down_fork_cnt per stack
        stack_ = form_stack_(y, P_, frame)

    while stack_:  # frame ends, last-line stacks are merged into their blobs:
        form_blob(stack_.popleft(), frame)

    return frame  # frame of blobs
Exemplo n.º 2
0
def image_to_blobs(
    image
):  # root function, segments frame into blobs of same ternary sign: der+ | rng+ | null

    gdert__, rdert__ = comp_pixel(
        image
    )  # gderts from 2x2 and rderts from 3x3 cross-comparison / cross-correlation
    s__, vg__, vg3__ = calc_sign(gdert__[1], rdert__[1])

    frame = dict(rng=1,
                 gdert__=gdert__,
                 rdert__=rdert__,
                 mask=None,
                 I=0,
                 G=0,
                 Dy=0,
                 Dx=0,
                 blob_=[])
    stack_ = deque()  # buffer of running vertical stacks of Ps
    height, width = rdert__.shape[1:]

    for y in range(height):  # first and last row are discarded
        print(f'Processing line {y}...')
        P_ = form_P_(s__[y], vg__[y], vg3__[y], gdert__[:, y + 1].T,
                     rdert__[:, y].T)  # horizontal clustering,
        # or rdert__[-1:, y-1].T, for 2x2 gdert in lower-right?
        P_ = scan_P_(
            P_, stack_, frame
        )  # vertical clustering, adds up_forks per P and down_fork_cnt per stack
        stack_ = form_stack_(y, P_, frame)

    while stack_:  # frame ends, last-line stacks are merged into their blobs:
        form_blob(stack_.popleft(), frame)

    return frame  # frame of blobs
Exemplo n.º 3
0
                dert__ = comp_r(dert__, fig=1, root_fcr=1)

    return dert__


# -----------------------------------------------------------------------------
# Main

if __name__ == "__main__":
    # Initial comp:
    print('Reading image...')
    image = imread(IMAGE_PATH)
    print('Done!')

    print('Doing first comp...')
    dert_ = comp_pixel(image)
    print('Done!')
    frame = image_to_blobs(image)

    for blob in frame['blob_']:
        # flags for forking
        fga = 0
        root_fcr = 0
        fig = 0

        blob['dert__'], fga, root_fcr, fig = layer_1(blob['dert__'],
                                                     blob['Dert']['G'],
                                                     blob['Dert']['M'], fga,
                                                     root_fcr, fig)
        blob['Dert']['M'] = ave - blob['Dert']['M']