def test5_1():
    """
    This functions builds a planar mesh and compute the associated
    weights matrix:
        ________________
        |\      |      /|
        |  \   0.5   /  |
        |    \  |  /    |
        |_0.5__\|/__0.5_|
        |      /|\      |
        |    /  |  \    |
        |  /   0.5   \  |
        |/______|______\|
    
    
    Then, the smoothing parameters are computed according to the given FWHM.
    The function checks that the computed parameters are correct.
    
    """
    # create vertices
    x = np.array([0., 1., 2.])
    x = np.repeat(x, 3)
    y = np.array([0., 1., 2.])
    y = np.tile(y ,3)
    z = np.zeros(9)
    vertices = np.vstack((x, y, z)).T
    
    # create polygons
    polygons = np.array([[0, 3, 4], [0, 4, 1], [1, 4, 2], [2, 4, 5],
                         [3, 6, 4], [4, 6, 7], [4, 7, 8], [4, 8, 5]])
    
    # get edges
    nb_edges = 3 * polygons.shape[0]
    edges = np.zeros((nb_edges, 2))
    # get the polygons edges as tuples
    permutator = np.array([(0,0,1),(1,0,0),(0,1,0)], dtype=int)
    edges[:,0] = np.ravel(polygons)
    edges[:,1] = np.ravel(np.dot(polygons, permutator))
    ind = np.lexsort((edges[:,1], edges[:,0]))
    edges = edges[ind]

    weights_matrix = smooth.compute_weights_matrix(polygons, vertices, edges)
    dt_max = 1/np.amax(np.ravel(weights_matrix.sum(1)))
    dt_max /= 2
    for FWHM in np.arange(1, 20):
        N, dt = smooth.compute_smoothing_parameters(weights_matrix, FWHM)
        assert (FWHM == 4 * np.sqrt(np.log(2) * N * dt))
        N, dt = smooth.compute_smoothing_parameters(weights_matrix,
                                                    FWHM, dt_max)
        assert (FWHM == 4 * np.sqrt(np.log(2) * N * dt))
예제 #2
0
    # /!\ fixme : check that input_tex corresponds to the mesh
    print "  * Getting information from input texture"
    sys.stdout.flush()
    input_tex = tio.Texture(orig_tex_path).read(orig_tex_path)
    activation_data = input_tex.data
    activation_data[np.isnan(activation_data)] = 0
        
    ### Construct the weights matrix
    print "  * Computing the weights matrix"
    sys.stdout.flush()
    weights_matrix = smooth.compute_weights_matrix(polygons, vertices, edges)
        
    ### Define the Laplace-Beltrami operator
    LB_operator = smooth.define_LB_operator(weights_matrix)
        
    ### Compute the number of iterations needed
    N, dt = smooth.compute_smoothing_parameters(weights_matrix, FWHM)
        
    ### Apply smoothing
    print "  * Smoothing...(FWHM = %g)" %FWHM
    sys.stdout.flush()
    smoothed_activation_data = smooth.diffusion_smoothing(
        activation_data, LB_operator, N, dt)
    
    ### Write smoothed data into a new texture file
    print "  * Writing output texture"
    sys.stdout.flush()
    output_tex = tio.Texture(smoothed_tex_path, data=smoothed_activation_data)
    output_tex.write()