# tfg.image.matting.loss

<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#L223-L262) |

Computes the matting loss function based on the matting Laplacian.

    tfg.image.matting.loss(
        matte: type_alias.TensorLike,
        laplacian: type_alias.TensorLike,
        name: str = 'matting_loss'
    ) -> tf.Tensor

Computes the matting loss function based on the `laplacian` generated by the
`build_matrices` function which implements the approach proposed by Levin
et al. in "A Closed Form Solution to Natural Image Matting".

<br />

<br />

<br />

| ## Args ||
|---|---|
| `matte` | A tensor of shape `[B, H, W, 1]`. |
| `laplacian` | A tensor of shape `[B, H - pad, W - pad, size^2, size^2]` containing the Laplacian matrices computed by the `build_matrices` function, where `pad` is equal to `size - 1` and `size` is the patch size used to compute this tensor. |
| `name` | A name for this op. Defaults to "matting_loss". |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor containing a scalar value defining the matting loss. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the last dimension of `matte` is not 1. If `matte` is not of rank 4. If the last two dimensions of `laplacian` are not of the same size. If `laplacian` is not of rank 5. If `B` is different between `matte` and `laplacian`. |

<br />