ocrd_cis/ocropy/common.py
def borderclean_bin(binary, margin=4):
    """Remove components that are only contained within the margin.

    Given a binarized, inverted image as Numpy array `binary`,
    find those foreground components that do not exceed
    the top/bottom margins, and return a mask to remove them.
    (This can be used to get rid of ascenders and descenders from
    neighbouring regions/lines, which cannot be found by resegment()
    within the region/line.

    This should happen before deskewing, because the latter increases
    the margins by an unpredictable amount.)

    Return a Numpy array (with 0 for stay and 1 for remove).
    """
    h, w = binary.shape
    h1, w1 = min(margin, h//2 - 4), min(margin, w//2 - 4)
    h2, w2 = -h1 if h1 else h, -w1 if w1 else w
    mask = np.zeros(binary.shape, 'i')
    mask[h1:h2, w1:w2] = 1
    # use only the vertical margins (to which recognition is sensitive):
    # mask[h1:h2, :] = 1
    _, ncomps_before = morph.label(binary)
    binary = morph.keep_marked(binary, mask)
    _, ncomps_after = morph.label(binary)
    LOG.debug('black components before/after borderclean (margin=%d): %d/%d',
              margin, ncomps_before, ncomps_after)
    return (1 - binary)*(1 - mask)
Remove components that are only contained within the margin.

    Given a binarized, inverted image as Numpy array `binary`,
    find those foreground components that do not exceed
    the top/bottom margins, and return a mask to remove them.
    (This can be used to get rid of ascenders and descenders from
    neighbouring regions/lines, which cannot be found by resegment()
    within the region/line.

    This should happen before deskewing, because the latter increases
    the margins by an unpredictable amount.)

    Return a Numpy array (with 0 for stay and 1 for remove).
    
Remove components that are only contained within the margin.
Given a binarized, inverted image as Numpy array `binary`,
find those foreground components that do not exceed
the top/bottom margins, and return a mask to remove them.
(This can be used to get rid of ascenders and descenders from
neighbouring regions/lines, which cannot be found by resegment()
within the region/line.

This should happen before deskewing, because the latter increases
the margins by an unpredictable amount.)

Return a Numpy array (with 0 for stay and 1 for remove).
Remove components that are only contained within the margin . Given a binarized inverted image as Numpy array ` binary ` find those foreground components that do not exceed the top / bottom margins and return a mask to remove them . ( This can be used to get rid of ascenders and descenders from neighbouring regions / lines which cannot be found by resegment () within the region / line . This should happen before deskewing because the latter increases the margins by an unpredictable amount . ) Return a Numpy array ( with 0 for stay and 1 for remove ) .
def borderclean_bin(binary, margin=4):
    h, w = binary.shape
    h1, w1 = min(margin, h//2 - 4), min(margin, w//2 - 4)
    h2, w2 = -h1 if h1 else h, -w1 if w1 else w
    mask = np.zeros(binary.shape, 'i')
    mask[h1:h2, w1:w2] = 1
    _, ncomps_before = morph.label(binary)
    binary = morph.keep_marked(binary, mask)
    _, ncomps_after = morph.label(binary)
    LOG.debug('black components before/after borderclean (margin=%d): %d/%d',
              margin, ncomps_before, ncomps_after)
    return (1 - binary)*(1 - mask)
def borderclean_bin ( binary , margin = 4 ) : h , w = binary . shape h1 , w1 = min ( margin , h // 2 - 4 ) , min ( margin , w // 2 - 4 ) h2 , w2 = - h1 if h1 else h , - w1 if w1 else w mask = np . zeros ( binary . shape , 'i' ) mask [ h1 : h2 , w1 : w2 ] = 1 _ , ncomps_before = morph . label ( binary ) binary = morph . keep_marked ( binary , mask ) _ , ncomps_after = morph . label ( binary ) LOG . debug ( 'black components before/after borderclean (margin=%d): %d/%d' , margin , ncomps_before , ncomps_after ) return ( 1 - binary ) * ( 1 - mask )
Remove components that are only contained within the margin.
Remove components that are only contained within the margin .
"""Remove components that are only contained within the margin.

    Given a binarized, inverted image as Numpy array `binary`,
    find those foreground components that do not exceed
    the top/bottom margins, and return a mask to remove them.
    (This can be used to get rid of ascenders and descenders from
    neighbouring regions/lines, which cannot be found by resegment()
    within the region/line.

    This should happen before deskewing, because the latter increases
    the margins by an unpredictable amount.)

    Return a Numpy array (with 0 for stay and 1 for remove).
    """ # use only the vertical margins (to which recognition is sensitive): # mask[h1:h2, :] = 1
binary
margin