Пример #1
0
    def initialise_input(self, input_vf):
        """ Initialise class variable given an input vf """
        self.dimension = qr.check_is_vf(input_vf)
        self.omega = qr.get_omega(input_vf)

        self.vf = copy.deepcopy(input_vf)
        self.phi = np.zeros_like(self.vf)
Пример #2
0
def id_eulerian_like(input_vf):
    """
    :param input_vf: input vector field.
    :return: corresponding grid position, i.e. the identity vector field sampled in the input_vf grid matrix
    in Lagrangian coordinates.
    """
    qr.check_is_vf(input_vf)
    return id_eulerian(qr.get_omega(input_vf), t=input_vf.shape[3])
Пример #3
0
def scalar_dot_eulerian(sf_left,
                        vf_right_eul,
                        affine_left_right=None,
                        s_i_o=3,
                        mode='constant',
                        cval=0.0,
                        prefilter=False):

    omega_right = qr.get_omega(vf_right_eul)
    d = len(omega_right)

    if affine_left_right is not None:
        A_l, A_r = affine_left_right
        # multiply each point of the vector field by the transformation matrix
        vf_right_eul = matrices.matrix_vector_field_product(
            np.linalg.inv(A_l).dot(A_r), vf_right_eul)

    if d == 2:
        assert vf_right_eul.shape[:
                                  2] == sf_left.shape[::
                                                      -1], 'Shape inconsistency.'
        coord = [
            vf_right_eul[..., i].reshape(omega_right, order='F').T
            for i in range(d)
        ][::-1]
        result = np.zeros_like(sf_left)
    else:
        coord = [
            vf_right_eul[..., i].reshape(omega_right, order='F')
            for i in range(d)
        ]
        result = np.zeros_like(sf_left)

    ndimage.map_coordinates(sf_left,
                            coord,
                            output=result,
                            order=s_i_o,
                            mode=mode,
                            cval=cval,
                            prefilter=prefilter)

    return result
Пример #4
0
def lagrangian_dot_eulerian(vf_left_lag,
                            vf_right_eul,
                            affine_left_right=None,
                            s_i_o=2,
                            mode='constant',
                            cval=0.0,
                            prefilter=True,
                            add_right=True):

    omega_right = qr.get_omega(vf_right_eul)
    d = len(omega_right)

    if affine_left_right is not None:
        A_l, A_r = affine_left_right
        vf_right_eul = matrices.matrix_vector_field_product(
            np.linalg.inv(A_l).dot(A_r), vf_right_eul)

    coord = [
        vf_right_eul[..., i].reshape(omega_right, order='F') for i in range(d)
    ]
    result = np.squeeze(np.zeros_like(vf_left_lag))

    for i in range(d):  # see if the for can be avoided with tests.

        ndimage.map_coordinates(np.squeeze(vf_left_lag[..., i]),
                                coord,
                                output=result[..., i],
                                order=s_i_o,
                                mode=mode,
                                cval=cval,
                                prefilter=prefilter)
    if add_right:  # option for the scaling and squaring.
        return result.reshape(
            vf_left_lag.shape) + cs.eulerian_to_lagrangian(vf_right_eul)
    else:
        return result.reshape(vf_left_lag.shape)
Пример #5
0
def test_get_omega_from_vf_2d():
    assert_array_equal(qr.get_omega(np.zeros([10, 10, 1, 1, 2])), [10, 10])
Пример #6
0
def test_get_omega_from_vf_wrong_input():
    with assert_raises(IOError):
        qr.get_omega(np.zeros([10, 10, 10, 1, 2]))