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')
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')
from inception.image.analyze import * if __name__ == '__main__': import os import urllib, cStringIO from inception.image.image import Image urlfilepath = "../../../test/urls.txt" urls = [] if os.path.exists(urlfilepath): with open(urlfilepath) as fileobj: urls = [l.strip() for l in fileobj.readlines() if l.strip()] for url in urls: fileobj = cStringIO.StringIO(urllib.urlopen(url).read()) img = Image.from_any(fileobj) print validate_as_foreground(img), url
foregroundImage.filename = matteImage.filename # test the images for i in range(len(backgroundImages)): bg = backgroundImages[i] fg = i + 1 if (i < len(backgroundImages) - 1) else 0 fg = foregroundImages[fg] print("-------- Running on %s over %s ----------" % (os.path.basename(fg.filename), os.path.basename(bg.filename))) results = statadjust(fg.data, bg.data, intermediary_results=True) suffix = ['before_0','contrast_1','lum_2', 'cct_3','sat_4'] if not os.path.exists(testdir+'/results'): os.makedirs(testdir+'/results') for i, result in enumerate([fg.data] + results): print("Merging to form %s" % suffix[i]) merger = merge.MergeOperation([bg, Image.from_any(result)], offsets=[(0,0),(0,0)]).run() #merger = Image.from_any(result[..., 3]) merger.save(testdir + '/results/%s_%s.jpg' % (os.path.basename(bg.filename).rsplit('.',1)[0],suffix[i])) """ x = backgroundImages[0] Image.from_any(x.data).save(testdir+'/orig.png') newspace = srgb_to_linear(x.data) Image.from_any(linear_to_srgb(setlog2luminance(newspace, -2.5).clip(0,1))).save(testdir+'/foo.png') """ #x = Image.from_filepath("./a0711-WP_IMG_1592.jpg") #Image.from_any(x.data).save("orig.png") #Image.from_any(getluminance(x.data)).save("lum.png") #Image.from_any(srgb_to_linear(x.data)).save("linear.png") #Image.from_any(linear_to_srgb(srgb_to_linear(x.data))).save("roundtrip.png") #Image.from_any(hsv_to_rgb(rgb_to_hsv(x.data))).save("hsvround.png")