コード例 #1
0
ファイル: pageseg.py プロジェクト: david-leon/kraken
def compute_boxmap(binary, scale, threshold=(.5, 4), dtype='i'):
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    boxmap = np.zeros(binary.shape, dtype)
    for o in bysize:
        if sl.area(o)**.5 < threshold[0] * scale:
            continue
        if sl.area(o)**.5 > threshold[1] * scale:
            continue
        boxmap[o] = 1
    return boxmap
コード例 #2
0
ファイル: pageseg.py プロジェクト: tianyaqu/kraken
def compute_boxmap(binary, scale, threshold=(.5, 4), dtype='i'):
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    boxmap = np.zeros(binary.shape, dtype)
    for o in bysize:
        if sl.area(o)**.5 < threshold[0]*scale:
            continue
        if sl.area(o)**.5 > threshold[1]*scale:
            continue
        boxmap[o] = 1
    return boxmap
コード例 #3
0
ファイル: pageseg.py プロジェクト: mittagessen/kraken
def compute_boxmap(binary: np.array, scale: float, threshold: Tuple[float, int] = (.5, 4), dtype: str = 'i') -> np.array:
    """
    Returns grapheme cluster-like boxes based on connected components.
    """
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    boxmap = np.zeros(binary.shape, dtype)
    for o in bysize:
        if sl.area(o)**.5 < threshold[0]*scale:
            continue
        if sl.area(o)**.5 > threshold[1]*scale:
            continue
        boxmap[o] = 1
    return boxmap
コード例 #4
0
ファイル: pageseg.py プロジェクト: ucodai/kraken
def compute_boxmap(binary: np.array,
                   scale: float,
                   threshold: Tuple[float, int] = (.5, 4),
                   dtype: str = 'i') -> np.array:
    """
    Returns grapheme cluster-like boxes based on connected components.
    """
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    boxmap = np.zeros(binary.shape, dtype)
    for o in bysize:
        if sl.area(o)**.5 < threshold[0] * scale:
            continue
        if sl.area(o)**.5 > threshold[1] * scale:
            continue
        boxmap[o] = 1
    return boxmap
コード例 #5
0
ファイル: pageseg.py プロジェクト: david-leon/kraken
def estimate_scale(binary):
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    scalemap = np.zeros(binary.shape)
    for o in bysize:
        if np.amax(scalemap[o]) > 0:
            continue
        scalemap[o] = sl.area(o)**0.5
    scale = np.median(scalemap[(scalemap > 3) & (scalemap < 100)])
    return scale
コード例 #6
0
ファイル: pageseg.py プロジェクト: tianyaqu/kraken
def estimate_scale(binary):
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    scalemap = np.zeros(binary.shape)
    for o in bysize:
        if np.amax(scalemap[o]) > 0:
            continue
        scalemap[o] = sl.area(o)**0.5
    scale = np.median(scalemap[(scalemap > 3) & (scalemap < 100)])
    return scale
コード例 #7
0
ファイル: pageseg.py プロジェクト: ucodai/kraken
def estimate_scale(binary: np.array) -> float:
    """
    Estimates image scale based on number of connected components.
    """
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    scalemap = np.zeros(binary.shape)
    for o in bysize:
        if np.amax(scalemap[o]) > 0:
            continue
        scalemap[o] = sl.area(o)**0.5
    scale = np.median(scalemap[(scalemap > 3) & (scalemap < 100)])
    return scale
コード例 #8
0
ファイル: pageseg.py プロジェクト: mittagessen/kraken
def estimate_scale(binary: np.array) -> float:
    """
    Estimates image scale based on number of connected components.
    """
    objects = binary_objects(binary)
    bysize = sorted(objects, key=sl.area)
    scalemap = np.zeros(binary.shape)
    for o in bysize:
        if np.amax(scalemap[o]) > 0:
            continue
        scalemap[o] = sl.area(o)**0.5
    scale = np.median(scalemap[(scalemap > 3) & (scalemap < 100)])
    return scale