예제 #1
0
    def test_linear_coefficients_jacobian_random(self, size):
        """Tests the Jacobian of the linear_coefficients function."""
        tensor_shape = np.random.randint(size, 6, size=3)
        matte_init = np.random.uniform(0.0,
                                       1.0,
                                       size=tensor_shape.tolist() + [1])
        tensor_shape[1:3] -= (size - 1)
        num_coeffs = np.random.randint(2, 4)
        pseudo_inverse_init = np.random.uniform(0.0,
                                                1.0,
                                                size=tensor_shape.tolist() +
                                                [num_coeffs, size**2])
        matte = tf.convert_to_tensor(value=matte_init)
        pseudo_inverse = tf.convert_to_tensor(value=pseudo_inverse_init)

        a, b = matting.linear_coefficients(matte, pseudo_inverse)

        with self.subTest(name="matte_a"):
            self.assert_jacobian_is_correct(matte, matte_init, a)
        with self.subTest(name="matte_b"):
            self.assert_jacobian_is_correct(matte, matte_init, b)
        with self.subTest(name="pseudo_inverse_a"):
            self.assert_jacobian_is_correct(pseudo_inverse,
                                            pseudo_inverse_init, a)
        with self.subTest(name="pseudo_inverse_b"):
            self.assert_jacobian_is_correct(pseudo_inverse,
                                            pseudo_inverse_init, b)
예제 #2
0
    def test_linear_coefficients_reconstruction_opposite_images(self, size):
        """Tests that the matte can be reconstructed by using the coefficients ."""
        tensor_shape = np.random.randint(size, 6, size=3).tolist()
        image = np.random.uniform(0.0, 1.0, size=tensor_shape + [1])

        _, pseudo_inverse = matting.build_matrices(image, size=size)
        a, b = matting.linear_coefficients(1.0 - image, pseudo_inverse)
        reconstructed = matting.reconstruct(image, a, b)

        self.assertAllClose(1.0 - image, reconstructed, atol=1e-4)
예제 #3
0
 def b_fn(matte, pseudo_inverse):
     _, b = matting.linear_coefficients(matte, pseudo_inverse)
     return b
예제 #4
0
 def a_fn(matte, pseudo_inverse):
     a, _ = matting.linear_coefficients(matte, pseudo_inverse)
     return a