image = Image.from_filepath("../../../../test/images/cookiejar.jpg")
    #image = Image.from_filepath("../../../../test/images/buff_small.png")

    import time
    t1 = time.time()
    print("Starting")
    result = alphamatte(image.data)


    t2 = time.time()
    print("Done (in %2.2f seconds)!" % (t2-t1))
    filename = image.filename
    
    image.to_rgba()
    image[..., 3] = result
    
    """
    image = image[...,0]
    image = Image(image)
    image.to_rgb()
    image[..., 0] = result
    image[..., 1] = result
    image[..., 2] = result
    """
    
    from PIL import Image as PILImage
    green = Image.from_any(PILImage.new('RGBA', (image.shape[1], image.shape[0]), color=(0,255,0,255)))
    from inception.image.operation.merge import MergeOperation
    mop = MergeOperation([green, image]).run()
    mop.save(filename.rsplit('.',1)[0] + '_greencomp.png')
    Image.from_any(result).save(filename.rsplit('.',1)[0] + '_matte.png')
Example #2
0
    image = ScaleOperation(image, image.width/3.0).run()

    offset = 20, 200
    
    pickle_path = bg.filename.rsplit('.', 1)[0] + '.scene.pkl'
    #pickle_path = bg.filename.rsplit('/',1)[0] + '/definitive.vanishing.pkl'
    import cPickle
    if (os.path.exists(pickle_path)):
        with open(pickle_path, 'r') as f:
            sd = cPickle.load(f)
        print("Detected vanishing points (x,y,z): %s" % sd.get_vanishing_points())
        print("Focal length: %s" % sd.focal_length)
        print(sd.vpestimator.vanishing_points)
    else:
        sd = estimate_scene_description(bg)
        with open(pickle_path, 'w') as f:
            cPickle.dump(sd, f)
    bg.scene_description = sd
    
    shadow = Image.from_any(create_shadow(image, bg, offset=offset, scene_description=None, skip_soften=True))
    image[...,3] *= .5
    mop = MergeOperation([bg, shadow, image], offsets=[(0,0),(0,0),offset]).run()
    mop.save(filename.rsplit('.',1)[0] + '_shadowcomp.png')
    
    """
    green = Image.from_any(PILImage.new('RGBA', (image.shape[1], image.shape[0]), color=(0,255,0,255)))
    mop = MergeOperation([green, shadow]).run()
    mop.save(filename.rsplit('.',1)[0] + '_greencomp.png')
    """
    Image.from_any(shadow).save(filename.rsplit('.',1)[0] + '_matte.png')