ocrd_cis/ocropy/common.py
def compute_hlines(binary, scale,
                   hlminwidth=10,
                   images=None):
    """Finds (and removes) horizontal black lines.

    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``hlminwidth``, minimum width (in ``scale`` multiples)
    (Minimum width for non-contiguous separators applies piece-wise.)
    - ``images``, an optional same-size int array as a non-text mask
      (to be ignored in fg)
    
    Returns a same-size bool array as a separator mask.
    """
    ## with zero horizontal dilation, hlines would need
    ## to be perfectly contiguous (i.e. without noise
    ## from binarization):
    d1 = odd(max(1,scale/8))
    d0 = odd(max(1,scale/4))
    # TODO This does not cope well with slightly sloped or heavily fragmented lines
    horiz = binary
    # 1- close horizontally a little to make warped or
    #    noisily binarized horizontal lines survive:
    horiz = morph.rb_closing(horiz, (d0,d1))
    DSAVE('hlines1_h-closed', horiz+0.6*binary)
    # 2- open horizontally to remove everything
    #    that is horizontally non-contiguous:
    opened = morph.rb_opening(horiz, (1,hlminwidth*scale))
    DSAVE('hlines2_h-opened', opened+0.6*binary)
    # 3- reconstruct the losses up to a certain distance
    #    to avoid creeping into overlapping glyphs but still
    #    cover most of the line even if not perfectly horizontal
    # (it would be fantastic if we could calculate the
    #  distance transform with stronger horizontal weights)
    horiz = np.where(horiz, opened, 2)
    horiz = morph.spread_labels(horiz, maxdist=d1) % 2 | opened
    DSAVE('hlines3_reconstructed', horiz+0.6*binary)
    # 4- disregard parts from images; we don't want
    #    to compete/overlap with image objects too much,
    #    or waste our nbest on them
    if isinstance(images, np.ndarray):
        horiz = np.minimum(horiz,images==0)
        #horiz = morph.keep_marked(horiz, images==0)
        DSAVE('hlines5_noimages', horiz+0.6*binary)
    # 5- filter objects long enough:
    horiz = morph.select_regions(horiz, sl.width, min=hlminwidth*scale)
    DSAVE('hlines5_selected', horiz+0.6*binary)
    # 6- dilate vertically a little
    #    to get a smooth contour without gaps
    horiz = morph.r_dilation(horiz, (d0,odd(scale)))
    DSAVE('hlines6_v-dilated', horiz+0.6*binary)
    return horiz > 0
Finds (and removes) horizontal black lines.

    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``hlminwidth``, minimum width (in ``scale`` multiples)
    (Minimum width for non-contiguous separators applies piece-wise.)
    - ``images``, an optional same-size int array as a non-text mask
      (to be ignored in fg)
    
    Returns a same-size bool array as a separator mask.
    
Finds (and removes) horizontal black lines.

Returns a same-size bool array as a separator mask.
Finds ( and removes ) horizontal black lines . Returns a same - size bool array as a separator mask .
def compute_hlines(binary, scale,
                   hlminwidth=10,
                   images=None):
    d1 = odd(max(1,scale/8))
    d0 = odd(max(1,scale/4))
    horiz = binary
    horiz = morph.rb_closing(horiz, (d0,d1))
    DSAVE('hlines1_h-closed', horiz+0.6*binary)
    opened = morph.rb_opening(horiz, (1,hlminwidth*scale))
    DSAVE('hlines2_h-opened', opened+0.6*binary)
    horiz = np.where(horiz, opened, 2)
    horiz = morph.spread_labels(horiz, maxdist=d1) % 2 | opened
    DSAVE('hlines3_reconstructed', horiz+0.6*binary)
    if isinstance(images, np.ndarray):
        horiz = np.minimum(horiz,images==0)
        DSAVE('hlines5_noimages', horiz+0.6*binary)
    horiz = morph.select_regions(horiz, sl.width, min=hlminwidth*scale)
    DSAVE('hlines5_selected', horiz+0.6*binary)
    horiz = morph.r_dilation(horiz, (d0,odd(scale)))
    DSAVE('hlines6_v-dilated', horiz+0.6*binary)
    return horiz > 0
def compute_hlines ( binary , scale , hlminwidth = 10 , images = None ) : d1 = odd ( max ( 1 , scale / 8 ) ) d0 = odd ( max ( 1 , scale / 4 ) ) horiz = binary horiz = morph . rb_closing ( horiz , ( d0 , d1 ) ) DSAVE ( 'hlines1_h-closed' , horiz + 0.6 * binary ) opened = morph . rb_opening ( horiz , ( 1 , hlminwidth * scale ) ) DSAVE ( 'hlines2_h-opened' , opened + 0.6 * binary ) horiz = np . where ( horiz , opened , 2 ) horiz = morph . spread_labels ( horiz , maxdist = d1 ) % 2 | opened DSAVE ( 'hlines3_reconstructed' , horiz + 0.6 * binary ) if isinstance ( images , np . ndarray ) : horiz = np . minimum ( horiz , images == 0 ) DSAVE ( 'hlines5_noimages' , horiz + 0.6 * binary ) horiz = morph . select_regions ( horiz , sl . width , min = hlminwidth * scale ) DSAVE ( 'hlines5_selected' , horiz + 0.6 * binary ) horiz = morph . r_dilation ( horiz , ( d0 , odd ( scale ) ) ) DSAVE ( 'hlines6_v-dilated' , horiz + 0.6 * binary ) return horiz > 0
Finds (and removes) horizontal black lines.
Finds ( and removes ) horizontal black lines .
"""Finds (and removes) horizontal black lines.

    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``hlminwidth``, minimum width (in ``scale`` multiples)
    (Minimum width for non-contiguous separators applies piece-wise.)
    - ``images``, an optional same-size int array as a non-text mask
      (to be ignored in fg)
    
    Returns a same-size bool array as a separator mask.
    """ ## with zero horizontal dilation, hlines would need ## to be perfectly contiguous (i.e. without noise ## from binarization): # TODO This does not cope well with slightly sloped or heavily fragmented lines # 1- close horizontally a little to make warped or #    noisily binarized horizontal lines survive: # 2- open horizontally to remove everything #    that is horizontally non-contiguous: # 3- reconstruct the losses up to a certain distance #    to avoid creeping into overlapping glyphs but still #    cover most of the line even if not perfectly horizontal # (it would be fantastic if we could calculate the #  distance transform with stronger horizontal weights) # 4- disregard parts from images; we don't want #    to compete/overlap with image objects too much, #    or waste our nbest on them #horiz = morph.keep_marked(horiz, images==0) # 5- filter objects long enough: # 6- dilate vertically a little #    to get a smooth contour without gaps
binary
scale
hlminwidth
images