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
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
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
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
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
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