예제 #1
0
def compute_lines(segmentation, spread, scale):
    """Given a line segmentation map, computes a list
    of tuples consisting of 2D slices and masked images."""
    lobjects = morph.find_objects(segmentation)
    lines = []
    for i, o in enumerate(lobjects):
        if o is None:
            continue
        if sl.dim1(o) < 2 * scale or sl.dim0(o) < scale:
            continue
        mask = (segmentation[o] == i + 1)
        if np.amax(mask) == 0:
            continue
        result = record()
        result.label = i + 1
        result.bounds = o
        polygon = []
        if ((segmentation[o] != 0) == (segmentation[o] != i + 1)).any():
            ppoints = draw_polygon(spread[o], i + 1)
            ppoints = ppoints[1:] if ppoints else []
            polygon = [(o[0].start + p[0], o[1].start + p[1]) for p in ppoints]
        if not polygon:
            polygon = [(o[0].start, o[1].start), (o[0].stop, o[1].start),
                       (o[0].stop, o[1].stop), (o[0].start, o[1].stop)]
        result.polygon = polygon
        result.mask = mask
        lines.append(result)
    return lines
예제 #2
0
def compute_lines(segmentation, scale):
    """Given a line segmentation map, computes a list
    of tuples consisting of 2D slices and masked images."""
    lobjects = morph.find_objects(segmentation)
    lines = []
    for i, o in enumerate(lobjects):
        if o is None:
            continue
        if sl.dim1(o) < 2 * scale or sl.dim0(o) < scale:
            continue
        mask = (segmentation[o] == i + 1)
        if np.amax(mask) == 0:
            continue
        result = record()
        result.label = i + 1
        result.bounds = o
        result.mask = mask
        lines.append(result)
    return lines
예제 #3
0
파일: pageseg.py 프로젝트: tianyaqu/kraken
def compute_lines(segmentation, scale):
    """Given a line segmentation map, computes a list
    of tuples consisting of 2D slices and masked images."""
    lobjects = morph.find_objects(segmentation)
    lines = []
    for i, o in enumerate(lobjects):
        if o is None:
            continue
        if sl.dim1(o) < 2*scale or sl.dim0(o) < scale:
            continue
        mask = (segmentation[o] == i+1)
        if np.amax(mask) == 0:
            continue
        result = record()
        result.label = i+1
        result.bounds = o
        result.mask = mask
        lines.append(result)
    return lines