Exemplo n.º 1
0
def partsFromnSegs5(components):
    segments = unwrap(components)
    if len(segments) == 5:
        return (1, 1, 1, 1, 1)
    elif len(segments) == 4:
        widths = map(attrgetter("width"), segments)
        widest = general.argmax(widths)
        result = [1] * 4
        result[widest] = 2
        return result
    elif len(segments) == 3:
        widths = map(attrgetter("width"), segments)
        narrowest = float(min(widths))
        reduced = map(lambda width: width / narrowest, widths)
        distances = map(lambda exp: distance(exp, reduced), five3)
        #print widths, narrowest, reduced, zip(distances, five3)
        return five3[general.argmin(distances)]
    elif len(segments) == 2:
        w0, w1 = segments[0].width, segments[1].width
        frac = float(w0) / float(w1)
        if frac < 1.0: frac = 1.0 / frac
        if frac > 2.75: return (4, 1) if w0 > w1 else (1, 4)
        else: return (3, 2) if w0 > w1 else (2, 3)
    elif len(segments) == 1:
        return (5, )
    else: return (1, ) * len(segments) # raise ValueError("Incorrect number of components: %d" % (len(segments)))
Exemplo n.º 2
0
 def adjust(splitter):
     if splitter == 0 or splitter == image.width - 1:
         return splitter
     neighborhood = projection[splitter - projRadius : splitter + projRadius + 1]
     return general.argmin(neighborhood) + splitter - projRadius