diffeo_list = pickle.load(open(dfile, 'rb')).actions pdb.set_trace() for i in range(len(diffeo_list)): D = diffeo_list[i].diffeo pdb.set_trace() logfile.write('<tr>') cmdstr = str(diffeo_list[i].original_cmd).replace(' ', '') # outpath+prefix+'diffeo'+cmdstr+'angle'+'.png' logfile.write('<td>') logfile.write(cmdstr) logfile.write('</td>') Image.fromarray(diffeo_to_rgb_angle(D.d)).save(outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png' + '"/>') logfile.write('</td>') Image.fromarray(diffeo_to_rgb_norm(D.d)).save(outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png' + '"/>') logfile.write('</td>') Image.fromarray((D.variance * 255).astype(np.uint8)).save(outpath + prefix + 'diffeo' + cmdstr + 'variance' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'variance' + '.png' + '"/>') logfile.write('</td>') Y = im Image.fromarray(Y).save(outpath + prefix + cmdstr + str(0) + '.png')
def symdiffeo_display(report, template_rgb, diffeo, resolution): # @UnusedVariable shape = [resolution, resolution] # This must be in the -1,1 -> -1,1 domain # change_basis = LinearCoordinateChange([[0, 1], [0, 1]], # [[-1, +1], [-1, +1]]) # diffeo2 = change_basis.conjugate(diffeo) viewport = SquareDomain([[-1, +1], [-1, +1]]) manifold = diffeo.get_topology() D, Dinfo = diffeo_from_function_viewport(diffeo, manifold, viewport, shape) D2d = Diffeomorphism2D(D, Dinfo) def function(p): q = diffeo(np.array(p)) q = manifold.normalize(q) return (q[0], q[1]) fig = report.figure(cols=4) M = 1 n1 = 10 n2 = 100 bx = [-.99, +.99] # depends on fmod by = bx params = dict(figsize=(3, 3)) def common_settings(pylab): pylab.axis('equal') pylab.axis((-M, M, -M, M)) turn_all_axes_off(pylab) with fig.plot('grid1', **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k.', vcol='k.') common_settings(pylab) with fig.plot('grid2', caption="different colors", **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r.', vcol='b.') common_settings(pylab) with fig.plot('grid3', caption="smiley (might be deformed in some cases)", **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r.', vcol='b.') common_settings(pylab) plot_smiley(curved) with fig.plot('grid4', caption="smiley (might be deformed in some cases)", **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k.', vcol='k.') common_settings(pylab) plot_smiley(curved, '0.5') fig = report.figure( cols=4, caption='Visualization of the diffeomorphism.' 'Note: must transpose rgb data on diagonal to make it coherent with' ' plots above.') # TODO: use code in diffeomoprhism2d report.data_rgb( 'norm_D', diffeo_to_rgb_norm(D), caption= "Norm(D). white=0, blue=maximum. Note: wrong in case of wraparound" ).add_to(fig) report.data_rgb( 'phase_D', diffeo_to_rgb_angle(D), caption="Phase(D). Note: wrong in case of wraparound").add_to(fig) def info2rgb(x): return scale(x, max_value=1, min_value=0, min_color=[1, 0, 0], max_color=[0, 1, 0]) report.data_rgb( 'D_info', info2rgb(Dinfo), caption='Uncertainty (green=sure, red=unknown)').add_to(fig) report.data_rgb('curvD', diffeo_to_rgb_curv(D)).add_to(fig) if template_rgb is not None: iterations = 3 im = template_rgb var = np.ones((im.shape[0], im.shape[1])) # XXX: use global code data = [(im, var)] for it in range(iterations): im, var = D2d.apply(im, var) data.append((im, var)) k = 0 for im, var in data: fig = report.figure(cols=4, caption='Effect on template (iteration %d)' % k) fig.data_rgb('im%d' % (it + 1), im) fig.data_rgb('var%d' % (it + 1), info2rgb(var)) k += 1
def symdiffeo_display(report, template_rgb, diffeo, resolution): #@UnusedVariable shape = [resolution, resolution] # This must be in the -1,1 -> -1,1 domain #change_basis = LinearCoordinateChange([[0, 1], [0, 1]], # [[-1, +1], [-1, +1]]) #diffeo2 = change_basis.conjugate(diffeo) viewport = SquareDomain([[-1, +1], [-1, +1]]) manifold = diffeo.get_topology() D, Dinfo = diffeo_from_function_viewport(diffeo, manifold, viewport, shape) D2d = Diffeomorphism2D(D, Dinfo) def function(p): q = diffeo(np.array(p)) q = manifold.normalize(q) return (q[0], q[1]) fig = report.figure(cols=4) M = 1 n1 = 10 n2 = 100 bx = [-.99, +.99] # depends on fmod by = bx params = dict(figsize=(3, 3)) def common_settings(pylab): pylab.axis('equal') pylab.axis((-M, M, -M, M)) turn_all_axes_off(pylab) with fig.plot('grid1', **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k.', vcol='k.') common_settings(pylab) with fig.plot('grid2', caption="different colors", **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r.', vcol='b.') common_settings(pylab) with fig.plot('grid3', caption="smiley (might be deformed in some cases)", **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='r.', vcol='b.') common_settings(pylab) plot_smiley(curved) with fig.plot('grid4', caption="smiley (might be deformed in some cases)", **params) as pylab: curved = CurvedPylab(pylab, function) plot_grid(curved, n1=n1, n2=n2, bx=bx, by=by, hcol='k.', vcol='k.') common_settings(pylab) plot_smiley(curved, '0.5') fig = report.figure(cols=4, caption='Visualization of the diffeomorphism.' 'Note: must transpose rgb data on diagonal to make it coherent with' ' plots above.') # TODO: use code in diffeomoprhism2d report.data_rgb('norm_D', diffeo_to_rgb_norm(D), caption="Norm(D). white=0, blue=maximum. Note: wrong in case of wraparound").add_to(fig) report.data_rgb('phase_D', diffeo_to_rgb_angle(D), caption="Phase(D). Note: wrong in case of wraparound").add_to(fig) def info2rgb(x): return scale(x, max_value=1, min_value=0, min_color=[1, 0, 0], max_color=[0, 1, 0]) report.data_rgb('D_info', info2rgb(Dinfo), caption='Uncertainty (green=sure, red=unknown)').add_to(fig) report.data_rgb('curvD', diffeo_to_rgb_curv(D)).add_to(fig) if template_rgb is not None: iterations = 3 im = template_rgb var = np.ones((im.shape[0], im.shape[1])) # XXX: use global code data = [(im, var)] for it in range(iterations): im, var = D2d.apply(im, var) data.append((im, var)) k = 0 for im, var in data: fig = report.figure(cols=4, caption='Effect on template (iteration %d)' % k) fig.data_rgb('im%d' % (it + 1), im) fig.data_rgb('var%d' % (it + 1), info2rgb(var)) k += 1
def test_diffeo_main(argv): # Find diffeomorphisms file try: dfile = argv[argv.index('-dl') + 1] except ValueError: dfile = '/media/data/learned_diffeo/camera_ptz.dynamics.pickle' print 'Using diffeomorphism from file: ', dfile # Find diffeomorphisms file try: outpath = argv[argv.index('-o') + 1] except ValueError: outpath = '/media/data/tempimages/' print 'Saving images to path: ', outpath # Find output prefix file try: prefix = argv[argv.index('-p') + 1] except ValueError: prefix = 'logitech_cam_ptz' print 'Using prefix for output files: ', prefix # Find Input image try: infile = argv[argv.index('-im') + 1] except ValueError: infile = '/home/adam/git/surf12adam/diffeo_experiments/lighttower640.jpg' print 'Using image file: ', infile # Number of levels to apply try: levels = int(argv[argv.index('-l') + 1]) except ValueError: levels = 5 print 'Applying diffeomorphism ', levels, ' times' # Image size try: size = eval(argv[argv.index('-size') + 1]) except ValueError: size = [160, 120] print 'Image size: ', size logfile = open(outpath + prefix + 'log.html', 'w') logfile.write('<html><body><h1>Diffeomorphism test log: ' + dfile + '</h1>') logfile.write('Diffeomorphism file: ' + dfile + '<br/>') logfile.write('Test image: <br/><img src="' + infile + '.png"/><br/><br/>') logfile.write('<table>\n') logfile.write('<tr align="center">\n <td>Command</td>\n') logfile.write('<td>Diffeomorphism<br/>Angle</td>') logfile.write('<td>Diffeomorphism<br/>Norm</td>') logfile.write('<td>Diffeomorphism<br/>Variance</td>') for i in range(levels + 1): logfile.write('<td>' + str(i) + '</td>') logfile.write('</tr>') im = np.array(Image.open(infile).resize(size).getdata(), np.uint8).reshape((size[1], size[0], 3)) #Y0,Y1 = get_Y_pair((30,30),(0,0),(160,120),im) # pdb.set_trace() diffeo_list = pickle.load(open(dfile, 'rb')) # pdb.set_trace() for i in range(len(diffeo_list.actions)): # for D in diffeo_list: D = diffeo_list.actions[i].diffeo # pdb.set_trace() logfile.write('<tr>') cmdstr = str(diffeo_list.actions[i].original_cmd).replace(' ', '_') # cmdstr = str(D.command).replace(' ','') # outpath+prefix+'diffeo'+cmdstr+'angle'+'.png' logfile.write('<td>') logfile.write(str(cmdstr)) logfile.write('</td>') pim = Image.fromarray(diffeo_to_rgb_angle(D.d)) pim.save(outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png' + '"/>') logfile.write('</td>') pim = Image.fromarray(diffeo_to_rgb_norm(D.d)) pim.save(outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png' + '"/>') logfile.write('</td>') pim = Image.fromarray((D.variance * 255).astype(np.uint8)) pim.save(outpath + prefix + 'diffeo' + cmdstr + 'variance' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'variance' + '.png' + '"/>') logfile.write('</td>') Y = im Image.fromarray(Y).save(outpath + prefix + cmdstr + str(0) + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + cmdstr + str(0) + '.png' + '"/>') logfile.write('</td>') for i in range(levels): Y, _ = D.apply(Y) Image.fromarray(Y).save(outpath + prefix + cmdstr + str(i + 1) + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + cmdstr + str(i + 1) + '.png' + '"/>') logfile.write('</td>') logfile.write('</tr>') logfile.write('</table></body></html>') logfile.flush() logfile.close()
diffeo_list = pickle.load(open(dfile, 'rb')).actions pdb.set_trace() for i in range(len(diffeo_list)): D = diffeo_list[i].diffeo pdb.set_trace() logfile.write('<tr>') cmdstr = str(diffeo_list[i].original_cmd).replace(' ', '') # outpath+prefix+'diffeo'+cmdstr+'angle'+'.png' logfile.write('<td>') logfile.write(cmdstr) logfile.write('</td>') Image.fromarray(diffeo_to_rgb_angle( D.d)).save(outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png' + '"/>') logfile.write('</td>') Image.fromarray(diffeo_to_rgb_norm(D.d)).save(outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png' + '"/>') logfile.write('</td>') Image.fromarray( (D.variance * 255).astype(np.uint8)).save(outpath + prefix + 'diffeo' + cmdstr + 'variance' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr +
def display_diffeo_images(diff): Image.fromarray(diffeo_to_rgb_angle(diff)).resize((400, 300)).show() Image.fromarray(diffeo_to_rgb_norm(diff)).resize((400, 300)).show()
def test_diffeo_main(argv): # Find diffeomorphisms file try: dfile = argv[argv.index('-dl') + 1] except ValueError: dfile = '/media/data/learned_diffeo/camera_ptz.dynamics.pickle' print 'Using diffeomorphism from file: ', dfile # Find diffeomorphisms file try: outpath = argv[argv.index('-o') + 1] except ValueError: outpath = '/media/data/tempimages/' print 'Saving images to path: ', outpath # Find output prefix file try: prefix = argv[argv.index('-p') + 1] except ValueError: prefix = 'logitech_cam_ptz' print 'Using prefix for output files: ', prefix # Find Input image try: infile = argv[argv.index('-im') + 1] except ValueError: infile = '/home/adam/git/surf12adam/diffeo_experiments/lighttower640.jpg' print 'Using image file: ', infile # Number of levels to apply try: levels = int(argv[argv.index('-l') + 1]) except ValueError: levels = 5 print 'Applying diffeomorphism ', levels, ' times' # Image size try: size = eval(argv[argv.index('-size') + 1]) except ValueError: size = [160, 120] print 'Image size: ', size logfile = open(outpath + prefix + 'log.html', 'w') logfile.write('<html><body><h1>Diffeomorphism test log: ' + dfile + '</h1>') logfile.write('Diffeomorphism file: ' + dfile + '<br/>') logfile.write('Test image: <br/><img src="' + infile + '.png"/><br/><br/>') logfile.write('<table>\n') logfile.write('<tr align="center">\n <td>Command</td>\n') logfile.write('<td>Diffeomorphism<br/>Angle</td>') logfile.write('<td>Diffeomorphism<br/>Norm</td>') logfile.write('<td>Diffeomorphism<br/>Variance</td>') for i in range(levels + 1): logfile.write('<td>' + str(i) + '</td>') logfile.write('</tr>') im = np.array(Image.open(infile).resize(size).getdata(), np.uint8).reshape( (size[1], size[0], 3)) #Y0,Y1 = get_Y_pair((30,30),(0,0),(160,120),im) # pdb.set_trace() diffeo_list = pickle.load(open(dfile, 'rb')) # pdb.set_trace() for i in range(len(diffeo_list.actions)): # for D in diffeo_list: D = diffeo_list.actions[i].diffeo # pdb.set_trace() logfile.write('<tr>') cmdstr = str(diffeo_list.actions[i].original_cmd).replace(' ', '_') # cmdstr = str(D.command).replace(' ','') # outpath+prefix+'diffeo'+cmdstr+'angle'+'.png' logfile.write('<td>') logfile.write(str(cmdstr)) logfile.write('</td>') pim = Image.fromarray(diffeo_to_rgb_angle(D.d)) pim.save(outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'angle' + '.png' + '"/>') logfile.write('</td>') pim = Image.fromarray(diffeo_to_rgb_norm(D.d)) pim.save(outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'norm' + '.png' + '"/>') logfile.write('</td>') pim = Image.fromarray((D.variance * 255).astype(np.uint8)) pim.save(outpath + prefix + 'diffeo' + cmdstr + 'variance' + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + 'diffeo' + cmdstr + 'variance' + '.png' + '"/>') logfile.write('</td>') Y = im Image.fromarray(Y).save(outpath + prefix + cmdstr + str(0) + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + cmdstr + str(0) + '.png' + '"/>') logfile.write('</td>') for i in range(levels): Y, _ = D.apply(Y) Image.fromarray(Y).save(outpath + prefix + cmdstr + str(i + 1) + '.png') logfile.write('<td>') logfile.write('<img src="' + outpath + prefix + cmdstr + str(i + 1) + '.png' + '"/>') logfile.write('</td>') logfile.write('</tr>') logfile.write('</table></body></html>') logfile.flush() logfile.close()