Esempio n. 1
0
def subsetDigitization(poly, shift=None, size=None):
    """Sample poly with a regular grid at integer coordinates starting
    from (0,0) to the given size (which should be a Size2D object)."""

    if size == None:
        size = poly.boundingBox().size()
        size = (int(math.ceil(size[0])) + 2, int(math.ceil(size[1])) + 2)
        if not shift:
            shift = (0, 0)
        shift = numpy.asarray(shift) + (1, 1) - poly.boundingBox().begin()
        poly = Polygon(poly + shift)

    result = vigra.GrayImage(size)
    for p in vigra.meshIter(size):
        result[p] = poly.contains((p[0], p[1])) and 1 or 0
    return result
Esempio n. 2
0
def subsetDigitization(poly, shift = None, size = None):
    """Sample poly with a regular grid at integer coordinates starting
    from (0,0) to the given size (which should be a Size2D object)."""

    if size == None:
        size = poly.boundingBox().size()
        size = (int(math.ceil(size[0]))+2,
                int(math.ceil(size[1]))+2)
        if not shift:
            shift = (0, 0)
        shift = numpy.asarray(shift) + (1, 1) - poly.boundingBox().begin()
        poly = Polygon(poly + shift)

    result = vigra.GrayImage(size)
    for p in vigra.meshIter(size):
        result[p] = poly.contains((p[0], p[1])) and 1 or 0
    return result
Esempio n. 3
0
        if plot:
            self.g.plot(Gnuplot.Data(self.points,
                                     title = "discrete line", with_ = "lp 3"),
                        *self.dsl.plotItems())
        return result

if __name__ == "__main__":
    dsl = DigitalStraightLine(0, 1, 0)
    dsl.addPoint( 1,  0)
    dsl.addPoint(-1,  0)
    dsl.addPoint(-2, -1)

    from vigra import GrayImage, norm, meshIter

    gimg = GrayImage(50, 50)
    for p in meshIter(gimg.size()):
        gimg[p] = norm(p - Point2D(25, 25)) < 20 and 255 or 0

    import pixelmap
    cem = pixelmap.crackEdgeMap(gimg, False)
    crackPoly = cem.edge(2)
    fc = freeman(crackPoly)

    import Gnuplot
    def gpLine(points, with_ = "lines", **kwargs):
        return Gnuplot.Data(points, with_ = with_, **kwargs)

    g = Gnuplot.Gnuplot()
    g("set size ratio -1")

    ep = [p + offset(fc, i) for i, p in enumerate(list(crackPoly)[:-1])]