# tfg.image.matting.build_matrices

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/image/matting.py#L105-L165) |

Generates the closed form matting Laplacian.

    tfg.image.matting.build_matrices(
        image: type_alias.TensorLike,
        size: int = 3,
        eps: type_alias.Float = 1e-05,
        name: str = 'matting_build_matrices'
    ) -> Tuple[tf.Tensor, tf.Tensor]

Generates the closed form matting Laplacian as proposed by Levin et
al. in "A Closed Form Solution to Natural Image Matting". This function also
return the pseudo-inverse matrix allowing to retrieve the matting linear
coefficient.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `image` | A tensor of shape `[B, H, W, C]`. |
| `size` | An `int` representing the size of the patches used to enforce smoothness. |
| `eps` | A small number of type `float` to regularize the problem. |
| `name` | A name for this op. Defaults to "matting_build_matrices". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor of shape `[B, H - pad, W - pad, size^2, size^2]` containing the matting Laplacian matrices. A tensor of shape `[B, H - pad, W - pad, C + 1, size^2]` containing the pseudo-inverse matrices which can be used to retrieve the matting linear coefficients. The padding `pad` is equal to `size - 1`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If `image` is not of rank 4. |

<br />