ocrd_cis/ocropy/common.py
def compute_colseps_conv(binary, scale=1.0, csminheight=10, maxcolseps=2):
    """Find vertical whitespace corresponding to column separators by convolution and thresholding.
    
    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``csminheight``, minimum height (in ``scale`` multiples)
    - ``maxcolseps``, maximum number of separators to keep
    (Minimum height for non-contiguous separators applies piece-wise.)
    
    Returns a same-size bool array as separator mask.
    """
    LOG.debug("considering at most %g whitespace column separators", maxcolseps)
    # find vertical whitespace by thresholding
    smoothed = filters.gaussian_filter(1.0*binary,(scale,scale*0.5))
    #smoothed = filters.uniform_filter(smoothed,(5.0*scale,1))
    # avoid blurring small/protruding glyphs below threshold
    smoothed = np.maximum(smoothed, filters.uniform_filter(smoothed,(5.0*scale,1)))
    thresh = (smoothed<np.amax(smoothed)*0.1)
    # note: maximum is unreliable
    #thresh = (smoothed<np.median(smoothed)*0.4) # 0.7
    # but median is also unreliable (depends on how much background there is)
    # maybe best use hist, bins = np.histogram(smoothed); bins[scipy.signal.find_peaks(-hist)[0]]
    DSAVE("colwsseps1_thresh",thresh+binary*0.6)
    # find column edges by filtering
    grad = filters.gaussian_filter(1.0*binary,(scale,scale*0.5),order=(0,1))
    grad = filters.uniform_filter(grad,(10.0*scale,1)) # csminheight
    DSAVE("colwsseps2_grad-raw",grad)
    grad = (grad>0.5*np.amax(grad))
    DSAVE("colwsseps2_grad",grad)
    # combine dilated edges and whitespace
    seps = np.minimum(thresh,filters.maximum_filter(grad,(odd(10*scale),odd(5*scale))))
    DSAVE("colwsseps3_seps",seps+binary*0.6)
    # select only the biggest column separators
    seps = morph.select_regions(seps,sl.dim0,min=csminheight*scale,nbest=maxcolseps)
    DSAVE("colwsseps4_selected",seps+binary*0.6)
    return seps > 0
Find vertical whitespace corresponding to column separators by convolution and thresholding.
    
    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``csminheight``, minimum height (in ``scale`` multiples)
    - ``maxcolseps``, maximum number of separators to keep
    (Minimum height for non-contiguous separators applies piece-wise.)
    
    Returns a same-size bool array as separator mask.
    
Find vertical whitespace corresponding to column separators by convolution and thresholding.

Returns a same-size bool array as separator mask.
Find vertical whitespace corresponding to column separators by convolution and thresholding . Returns a same - size bool array as separator mask .
def compute_colseps_conv(binary, scale=1.0, csminheight=10, maxcolseps=2):
    LOG.debug("considering at most %g whitespace column separators", maxcolseps)
    smoothed = filters.gaussian_filter(1.0*binary,(scale,scale*0.5))
    smoothed = np.maximum(smoothed, filters.uniform_filter(smoothed,(5.0*scale,1)))
    thresh = (smoothed<np.amax(smoothed)*0.1)
    DSAVE("colwsseps1_thresh",thresh+binary*0.6)
    grad = filters.gaussian_filter(1.0*binary,(scale,scale*0.5),order=(0,1))
    grad = filters.uniform_filter(grad,(10.0*scale,1)) 
    DSAVE("colwsseps2_grad-raw",grad)
    grad = (grad>0.5*np.amax(grad))
    DSAVE("colwsseps2_grad",grad)
    seps = np.minimum(thresh,filters.maximum_filter(grad,(odd(10*scale),odd(5*scale))))
    DSAVE("colwsseps3_seps",seps+binary*0.6)
    seps = morph.select_regions(seps,sl.dim0,min=csminheight*scale,nbest=maxcolseps)
    DSAVE("colwsseps4_selected",seps+binary*0.6)
    return seps > 0
def compute_colseps_conv ( binary , scale = 1.0 , csminheight = 10 , maxcolseps = 2 ) : LOG . debug ( "considering at most %g whitespace column separators" , maxcolseps ) smoothed = filters . gaussian_filter ( 1.0 * binary , ( scale , scale * 0.5 ) ) smoothed = np . maximum ( smoothed , filters . uniform_filter ( smoothed , ( 5.0 * scale , 1 ) ) ) thresh = ( smoothed < np . amax ( smoothed ) * 0.1 ) DSAVE ( "colwsseps1_thresh" , thresh + binary * 0.6 ) grad = filters . gaussian_filter ( 1.0 * binary , ( scale , scale * 0.5 ) , order = ( 0 , 1 ) ) grad = filters . uniform_filter ( grad , ( 10.0 * scale , 1 ) ) DSAVE ( "colwsseps2_grad-raw" , grad ) grad = ( grad > 0.5 * np . amax ( grad ) ) DSAVE ( "colwsseps2_grad" , grad ) seps = np . minimum ( thresh , filters . maximum_filter ( grad , ( odd ( 10 * scale ) , odd ( 5 * scale ) ) ) ) DSAVE ( "colwsseps3_seps" , seps + binary * 0.6 ) seps = morph . select_regions ( seps , sl . dim0 , min = csminheight * scale , nbest = maxcolseps ) DSAVE ( "colwsseps4_selected" , seps + binary * 0.6 ) return seps > 0
Find vertical whitespace corresponding to column separators by convolution and thresholding.
Find vertical whitespace corresponding to column separators by convolution and thresholding .
"""Find vertical whitespace corresponding to column separators by convolution and thresholding.
    
    Parameters:
    - ``binary``, a bool or int array of the page image, with 1=black
    - ``scale``, square root of average bbox area of characters
    - ``csminheight``, minimum height (in ``scale`` multiples)
    - ``maxcolseps``, maximum number of separators to keep
    (Minimum height for non-contiguous separators applies piece-wise.)
    
    Returns a same-size bool array as separator mask.
    """ # find vertical whitespace by thresholding #smoothed = filters.uniform_filter(smoothed,(5.0*scale,1)) # avoid blurring small/protruding glyphs below threshold # note: maximum is unreliable #thresh = (smoothed<np.median(smoothed)*0.4) # 0.7 # but median is also unreliable (depends on how much background there is) # maybe best use hist, bins = np.histogram(smoothed); bins[scipy.signal.find_peaks(-hist)[0]] # find column edges by filtering # csminheight # combine dilated edges and whitespace # select only the biggest column separators
binary
scale
csminheight
maxcolseps