Example #1
0
def make_movie(c0, c1, theta0, movie_name, 
               m=2, dims=(-1.5, 1.5, -1.5, 1.5), numframes=100):
    """
    Create linear interpolation movie.
    """
    xmin, xmax, ymin, ymax = dims

    mp = MatchingProblem(c0, c1, m)
    g, res, n = mp.match(theta0)

    interp = LiegroupInterpolationMethod(c0, c1, g)

    # Generate frames
    for n in xrange(0, numframes):

        epsilon = float(n)/(numframes-1)
    
        c0_transformed = interp.transform(epsilon)
        im = LineImage(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax); 
        im.plot_curve(c0_transformed)
        im.save(TMP_FOLDER + 'still%04d.png' % n)
        im.close()

    # Compile movie
    cwd = os.getcwd()
    os.chdir(TMP_FOLDER)
    os.system('/Users/Joris/localsoft/bin/ffmpeg -i still%%04d.png %s' % movie_name)
    shutil.move(movie_name, cwd)
    os.chdir(cwd)
def digits_pairwise_match():
    """
    Find discrepancy and minimizing angle for each pair of digits.

    """

    discrepancy = np.empty((10, 10))
    theta_min = np.empty((10, 10))

    for m in xrange(0, 10):
        c0 = DiscreteCurve()
        c0.load(DATA_FOLDER + '/%d_processed.mat' % m)
        c0.translate(-c0[0,:])
    
        print "*** SOURCE: %d ***" % m
    
        for n in xrange(0, 10):
            c1 = DiscreteCurve()
            c1.load(DATA_FOLDER + '/%d_processed.mat' % n)
            c1.translate(-c1[0,:])
        
            print "*** TARGET: %d ***" % n
        
            mp = MatchingProblem(c0, c1, 2)
            energies = mp.sweep_theta_range(40)
        
            E_conv, E_div = separate_energies(energies)
            if len(E_conv) == 0:
                print "*** ERROR: No convergence for %d to %d ***" % (m, n)
        
            argmin = E_conv[:, 1].argmin()
            theta, E_min = E_conv[argmin, 0:2]
        
            print "* theta_min = %f, E_min = %f *" % (theta, E_min)
        
            discrepancy[m, n] = E_min
            theta_min[m, n] = theta

    return theta_min, discrepancy