ocrd_cis/ocropy/ocrolib/morph.py
def select_regions(binary,f,min=0,nbest=100000):
    """Given a scoring function f over slice tuples (as returned by
    find_objects), keeps at most nbest components whose scores is higher
    than min."""
    if binary.max() == 1:
        labels,_ = label(binary)
    else:
        labels = binary
    objects = find_objects(labels)
    scores = [f(o) for o in objects]
    best = argsort(scores)
    keep = zeros(len(objects)+1,'i')
    if nbest > 0:
        for i in best[-nbest:]:
            if scores[i]<=min: continue
            keep[i+1] = 1
    # print scores,best[-nbest:],keep
    # print sorted(list(set(labels.ravel())))
    # print sorted(list(set(keep[labels].ravel())))
    return keep[labels]
Given a scoring function f over slice tuples (as returned by
    find_objects), keeps at most nbest components whose scores is higher
    than min.
Given a scoring function f over slice tuples (as returned by
find_objects), keeps at most nbest components whose scores is higher
than min.
Given a scoring function f over slice tuples ( as returned by find_objects ) keeps at most nbest components whose scores is higher than min .
def select_regions(binary,f,min=0,nbest=100000):
    if binary.max() == 1:
        labels,_ = label(binary)
    else:
        labels = binary
    objects = find_objects(labels)
    scores = [f(o) for o in objects]
    best = argsort(scores)
    keep = zeros(len(objects)+1,'i')
    if nbest > 0:
        for i in best[-nbest:]:
            if scores[i]<=min: continue
            keep[i+1] = 1
    return keep[labels]
def select_regions ( binary , f , min = 0 , nbest = 100000 ) : if binary . max ( ) == 1 : labels , _ = label ( binary ) else : labels = binary objects = find_objects ( labels ) scores = [ f ( o ) for o in objects ] best = argsort ( scores ) keep = zeros ( len ( objects ) + 1 , 'i' ) if nbest > 0 : for i in best [ - nbest : ] : if scores [ i ] <= min : continue keep [ i + 1 ] = 1 return keep [ labels ]
Given a scoring function f over slice tuples (as returned by
find_objects), keeps at most nbest components whose scores is higher
than min.
Given a scoring function f over slice tuples ( as returned by find_objects ) keeps at most nbest components whose scores is higher than min .
"""Given a scoring function f over slice tuples (as returned by
    find_objects), keeps at most nbest components whose scores is higher
    than min.""" # print scores,best[-nbest:],keep # print sorted(list(set(labels.ravel()))) # print sorted(list(set(keep[labels].ravel())))
binary
f
min
nbest