Beispiel #1
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)
Beispiel #2
0
  def test_reconstruct_jacobian_random(self, channels):
    """Tests the Jacobian of the reconstruct function."""
    tensor_shape = np.random.randint(1, 5, size=3).tolist()
    image_init = np.random.uniform(0.0, 1.0, size=tensor_shape + [channels])
    mul_init = np.random.uniform(0.0, 1.0, size=tensor_shape + [channels])
    add_init = np.random.uniform(0.0, 1.0, size=tensor_shape + [1])
    image = tf.convert_to_tensor(value=image_init)
    mul = tf.convert_to_tensor(value=mul_init)
    add = tf.convert_to_tensor(value=add_init)

    reconstruction = matting.reconstruct(image, mul, add)

    with self.subTest(name="image"):
      self.assert_jacobian_is_correct(image, image_init, reconstruction)
    with self.subTest(name="coeff_mul"):
      self.assert_jacobian_is_correct(mul, mul_init, reconstruction)
    with self.subTest(name="coeff_add"):
      self.assert_jacobian_is_correct(add, add_init, reconstruction)