code: def build_matrices(
      image: type_alias.TensorLike,
      size: int = 3,
      eps: type_alias.Float = 1e-5,
      name: str = "matting_build_matrices",
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Generates the closed form matting Laplacian.
  
      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.
  
      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".
  
      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`.
  
      Raises:
        ValueError: If `image` is not of rank 4.
      """
      with tf.name_scope(name):
          image = tf.convert_to_tensor(value=image)
          eps = tf.constant(value=eps, dtype=image.dtype)
  
          shape.check_static(image, has_rank=4)
          if size % 2 == 0:
              raise ValueError(
                  "The patch size is expected to be an odd value."
              )
  
          pixels = size**2
          channels = tf.shape(input=image)[-1]
          dtype = image.dtype
          # Extracts image patches.
          patches = _image_patches(image, size)
          batches = tf.shape(input=patches)[:-1]
          patches = tf.reshape(
              patches, shape=_shape(batches, pixels, channels)
          )
          # Creates the data matrix block.
          ones = tf.ones(shape=_shape(batches, pixels, 1), dtype=dtype)
          affine = tf.concat((patches, ones), axis=-1)
          # Creates the regularizer matrix block.
          diag = tf.sqrt(eps) * tf.eye(
              channels, batch_shape=(1, 1, 1), dtype=dtype
          )
          zeros = tf.zeros(
              shape=_shape((1, 1, 1), channels, 1), dtype=dtype
          )
          regularizer = tf.concat((diag, zeros), axis=-1)
          regularizer = tf.tile(
              regularizer, multiples=_shape(batches, 1, 1)
          )
          # Creates a matrix concatenating the data and regularizer blocks.
          mat = tf.concat((affine, regularizer), axis=-2)
          # Builds the pseudo inverse and the laplacian matrices.
          inverse = tf.linalg.inv(tf.matmul(mat, mat, transpose_a=True))
          inverse = asserts.assert_no_infs_or_nans(inverse)
          pseudo_inverse = tf.matmul(inverse, affine, transpose_b=True)
          identity = tf.eye(num_rows=pixels, dtype=dtype)
          laplacian = identity - tf.matmul(affine, pseudo_inverse)
          return laplacian, pseudo_inverse
  
file_path: graphics/tensorflow_graphics/image/matting.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import List, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow_graphics.math import vector
  from tensorflow_graphics.util import asserts
  from tensorflow_graphics.util import export_api
  from tensorflow_graphics.util import shape
  from tensorflow_graphics.util import type_alias
label_desc: Use image node_id 5 for calling a global function with example usage: build_matrices(image, size, eps, name) and returns: laplacian,  pseudo_inverse