Beispiel #1
0
def mark_useg(mdata, map, pt, mark, structure):
    """
    Mark upward-connected region on segment map starting at node pt

    Parameters:
    
    * mdata Masked data array
    * map   Array mapping out segments
    * pt    Index of starting node
    * mark  Integer to mark map with.

    Returns nothing but modified mdata mask and map

    """
    if mdata.mask[pt] == True:
        return
    else:
        map[pt] = mark
        mdata[pt] = ma.masked

    Q = [pt]
    while Q:
        pt = Q.pop(0)
        v = mdata.data[pt]

        # Check all neightbors
        for new_pt in neighbors(pt, mdata.shape, structure):
            if mdata.mask[new_pt] == False and mdata[new_pt] > v:
                Q.append(new_pt)
                map[new_pt] = mark
                mdata[new_pt] = ma.masked
    return
Beispiel #2
0
def mark_useg(mdata, map, pt, mark, structure):
    """
    Mark upward-connected region on segment map starting at node pt

    Parameters:
    
    * mdata Masked data array
    * map   Array mapping out segments
    * pt    Index of starting node
    * mark  Integer to mark map with.

    Returns nothing but modified mdata mask and map

    """
    if mdata.mask[pt] == True:
        return
    else:
        map[pt] = mark
        mdata[pt] = ma.masked

    Q = [pt]
    while Q:
        pt = Q.pop(0)
        v = mdata.data[pt]

        # Check all neightbors
        for new_pt in neighbors(pt, mdata.shape, structure):
            if mdata.mask[new_pt] == False and mdata[new_pt] > v:
                Q.append(new_pt)
                map[new_pt] = mark
                mdata[new_pt] = ma.masked
    return
Beispiel #3
0
def find_upward(data, pt, thres, diag=False):
    """
    Find points upward-connected to pt in data.

    Parameters:

    * data  2D array of data
    * pt    Starting point, bottom of peak, tuple.
    * thres Threshold, above this nodes are considered noise.
    * diag  True or False to include diagonal neighbors in connection.

    Return: list of indicies of upward connected nodes.

    """
    # build structure array for defining feature connections
    ndim = data.ndim
    if diag:
        structure = ndimage.generate_binary_structure(ndim, ndim)
    else:
        structure = ndimage.generate_binary_structure(ndim, 1)

    if type(pt) == int:
        pt = (pt, )
    pt = tuple(pt)
    shape = data.shape

    if data[pt] > thres:  # check that the initial point is below threshold.
        return []

    Q = [pt]  # queue
    segment = [pt]

    while Q:  # loop until Q is empty
        pt = Q.pop(0)  # remove first element of queue
        v = data[pt]  # value at current node

        for new_pt in neighbors(pt, shape, structure):  # check all neightbors

            if thres > data[new_pt] > v and new_pt not in segment:
                Q.append(new_pt)
                segment.append(new_pt)

    return segment
Beispiel #4
0
def find_upward(data, pt, thres, diag=False):
    """
    Find points upward-connected to pt in data.

    Parameters:

    * data  2D array of data
    * pt    Starting point, bottom of peak, tuple.
    * thres Threshold, above this nodes are considered noise.
    * diag  True or False to include diagonal neighbors in connection.

    Return: list of indicies of upward connected nodes.

    """
    # build structure array for defining feature connections
    ndim = data.ndim
    if diag:
        structure = ndimage.generate_binary_structure(ndim, ndim)
    else:
        structure = ndimage.generate_binary_structure(ndim, 1)

    if type(pt) == int:
        pt = (pt,)
    pt = tuple(pt)
    shape = data.shape

    if data[pt] > thres:  # check that the initial point is below threshold.
        return []

    Q = [pt]  # queue
    segment = [pt]

    while Q:  # loop until Q is empty
        pt = Q.pop(0)  # remove first element of queue
        v = data[pt]  # value at current node

        for new_pt in neighbors(pt, shape, structure):  # check all neightbors

            if thres > data[new_pt] > v and new_pt not in segment:
                Q.append(new_pt)
                segment.append(new_pt)

    return segment