예제 #1
0
파일: dumpsc.py 프로젝트: madl-ash/cocdp
def extractimg(im, poly):
    path= PIL.ImagePath.Path(poly)
    bb= path.getbbox()
    bbsize= (abs(bb[2]-bb[0]), abs(bb[3]-bb[1]))
    tx= PIL.ImageTransform.ExtentTransform(path.getbbox())

    newimg= im.transform(bbsize, tx)

    # update path to match 'newimg'
    path.map(lambda x,y:(x-bb[0], y-bb[1]))

    # now clear pixels outside poly

    img= PIL.Image.new("RGBA", bbsize)
    img.paste(newimg, createmask(path))

    return img
예제 #2
0
def extractimg(im, poly):
    path = PIL.ImagePath.Path(poly)
    bb = path.getbbox()
    bbsize = (abs(bb[2] - bb[0]), abs(bb[3] - bb[1]))
    tx = PIL.ImageTransform.ExtentTransform(path.getbbox())

    newimg = im.transform(bbsize, tx)

    # update path to match 'newimg'
    path.map(lambda x, y: (x - bb[0], y - bb[1]))

    # now clear pixels outside poly

    img = PIL.Image.new("RGBA", bbsize)
    img.paste(newimg, createmask(path))

    return img
예제 #3
0
파일: dumpsc.py 프로젝트: madl-ash/cocdp
def createmask(path):
    bb= path.getbbox()
    bbsize= (abs(bb[2]-bb[0]), abs(bb[3]-bb[1]))
    img= PIL.Image.new("1", bbsize)
    draw= PIL.ImageDraw.Draw(img)

    draw.polygon(path, fill=1)

    return img
예제 #4
0
def createmask(path):
    bb = path.getbbox()
    bbsize = (abs(bb[2] - bb[0]), abs(bb[3] - bb[1]))
    img = PIL.Image.new("1", bbsize)
    draw = PIL.ImageDraw.Draw(img)

    draw.polygon(path, fill=1)

    return img