ocrd_cis/ocropy/common.py
def compute_separators_morph(binary, scale,
                             maxseps=2,
                             csminheight=10,
                             images=None):
    """Finds vertical black lines corresponding to column separators.

    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``maxseps``, maximum number of black separators to keep
    - ``csminheight``, minimum height (in ``scale`` multiples)
    (Non-contiguous separator lines count piece-wise. Equally,
     minimum height 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 separator mask.
    """
    LOG.debug("considering at most %g black column separators", maxseps)
    ## no large vertical dilation here, because
    ## that would turn letters into lines; but
    ## with zero vertical share, vlines would need
    ## to be perfectly contiguous (i.e. without any
    ## noise from binarization etc):
    d0 = odd(max(1,scale/4))
    d1 = odd(max(1,scale/8))
    # TODO This does not cope well with slightly sloped or heavily fragmented lines
    vert = binary
    # 1- close vertically a little to make warped or
    #    noisily binarized vertical lines survive:
    vert = morph.rb_closing(vert, (d0,d1))
    DSAVE('colseps1_v-closed', vert+0.6*binary)
    # 2- open vertically to remove everything that
    #    is vertically non-contiguous:
    opened = morph.rb_opening(vert, (csminheight*scale,1))
    DSAVE('colseps2_v-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 vertical
    # (it would be fantastic if we could calculate the
    #  distance transform with stronger vertical weights)
    vert = np.where(vert, opened, 2)
    vert = morph.spread_labels(vert, maxdist=d1) % 2 | opened
    DSAVE('colseps3_reconstructed', vert+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):
        vert = np.minimum(vert,images==0)
        #vert = morph.keep_marked(vert, images==0)
        DSAVE('colseps4_noimages', vert+0.6*binary)
    # 5- select the n widest and highest segments
    #    above certain thresholds to be vertical lines:
    ## min=1 instead of 3, because lines can be 1 pixel thin
    vert = morph.select_regions(vert,sl.dim1,min=1,nbest=4* maxseps)
    vert = morph.select_regions(vert,sl.dim0,min=csminheight*scale,nbest=maxseps)
    DSAVE('colseps5_selected', vert+0.6*binary)
    # 6- dilate horizontally a little
    #    to get a smooth contour without gaps
    vert = morph.r_dilation(vert, (odd(scale),d1))
    DSAVE('colseps6_h-dilated', vert+0.6*binary)
    return vert > 0
Finds vertical black lines corresponding to column separators.

    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``maxseps``, maximum number of black separators to keep
    - ``csminheight``, minimum height (in ``scale`` multiples)
    (Non-contiguous separator lines count piece-wise. Equally,
     minimum height 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 separator mask.
    
Finds vertical black lines corresponding to column separators.

Returns a same-size bool array as separator mask.
Finds vertical black lines corresponding to column separators . Returns a same - size bool array as separator mask .
def compute_separators_morph(binary, scale,
                             maxseps=2,
                             csminheight=10,
                             images=None):
    LOG.debug("considering at most %g black column separators", maxseps)
    d0 = odd(max(1,scale/4))
    d1 = odd(max(1,scale/8))
    vert = binary
    vert = morph.rb_closing(vert, (d0,d1))
    DSAVE('colseps1_v-closed', vert+0.6*binary)
    opened = morph.rb_opening(vert, (csminheight*scale,1))
    DSAVE('colseps2_v-opened', opened+0.6*binary)
    vert = np.where(vert, opened, 2)
    vert = morph.spread_labels(vert, maxdist=d1) % 2 | opened
    DSAVE('colseps3_reconstructed', vert+0.6*binary)
    if isinstance(images, np.ndarray):
        vert = np.minimum(vert,images==0)
        DSAVE('colseps4_noimages', vert+0.6*binary)
    vert = morph.select_regions(vert,sl.dim1,min=1,nbest=4* maxseps)
    vert = morph.select_regions(vert,sl.dim0,min=csminheight*scale,nbest=maxseps)
    DSAVE('colseps5_selected', vert+0.6*binary)
    vert = morph.r_dilation(vert, (odd(scale),d1))
    DSAVE('colseps6_h-dilated', vert+0.6*binary)
    return vert > 0
def compute_separators_morph ( binary , scale , maxseps = 2 , csminheight = 10 , images = None ) : LOG . debug ( "considering at most %g black column separators" , maxseps ) d0 = odd ( max ( 1 , scale / 4 ) ) d1 = odd ( max ( 1 , scale / 8 ) ) vert = binary vert = morph . rb_closing ( vert , ( d0 , d1 ) ) DSAVE ( 'colseps1_v-closed' , vert + 0.6 * binary ) opened = morph . rb_opening ( vert , ( csminheight * scale , 1 ) ) DSAVE ( 'colseps2_v-opened' , opened + 0.6 * binary ) vert = np . where ( vert , opened , 2 ) vert = morph . spread_labels ( vert , maxdist = d1 ) % 2 | opened DSAVE ( 'colseps3_reconstructed' , vert + 0.6 * binary ) if isinstance ( images , np . ndarray ) : vert = np . minimum ( vert , images == 0 ) DSAVE ( 'colseps4_noimages' , vert + 0.6 * binary ) vert = morph . select_regions ( vert , sl . dim1 , min = 1 , nbest = 4 * maxseps ) vert = morph . select_regions ( vert , sl . dim0 , min = csminheight * scale , nbest = maxseps ) DSAVE ( 'colseps5_selected' , vert + 0.6 * binary ) vert = morph . r_dilation ( vert , ( odd ( scale ) , d1 ) ) DSAVE ( 'colseps6_h-dilated' , vert + 0.6 * binary ) return vert > 0
Finds vertical black lines corresponding to column separators.
Finds vertical black lines corresponding to column separators .
"""Finds vertical black lines corresponding to column separators.

    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``maxseps``, maximum number of black separators to keep
    - ``csminheight``, minimum height (in ``scale`` multiples)
    (Non-contiguous separator lines count piece-wise. Equally,
     minimum height 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 separator mask.
    """ ## no large vertical dilation here, because ## that would turn letters into lines; but ## with zero vertical share, vlines would need ## to be perfectly contiguous (i.e. without any ## noise from binarization etc): # TODO This does not cope well with slightly sloped or heavily fragmented lines # 1- close vertically a little to make warped or #    noisily binarized vertical lines survive: # 2- open vertically to remove everything that #    is vertically 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 vertical # (it would be fantastic if we could calculate the #  distance transform with stronger vertical weights) # 4- disregard parts from images; we don't want #    to compete/overlap with image objects too much, #    or waste our nbest on them #vert = morph.keep_marked(vert, images==0) # 5- select the n widest and highest segments #    above certain thresholds to be vertical lines: ## min=1 instead of 3, because lines can be 1 pixel thin # 6- dilate horizontally a little #    to get a smooth contour without gaps
binary
scale
maxseps
csminheight
images