code: def distortion_factor(
      squared_radius: type_alias.TensorLike,
      distortion_coefficient: type_alias.TensorLike,
      name: str = "quadratic_radial_distortion_distortion_factor",
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Calculates a quadratic distortion factor given squared radii.
  
      Given a vector describing a location in camera space in homogeneous
      coordinates, `(x/z, y/z, 1)`, squared_radius is `r^2 = (x/z)^2 + (y/z)^2`.
      distortion_factor multiplies `x/z` and `y/z` to obtain the distorted
      coordinates. In this function, `distortion_factor` is given by
      `1.0 + distortion_coefficient * squared_radius`.
  
      Note:
        In the following, A1 to An are optional batch dimensions, which must be
        broadcast compatible.
  
      Args:
        squared_radius: A tensor of shape `[A1, ..., An, H, W]`, containing the
          radii of the image pixels computed as `(x/z)^2 + (y/z)^2`. We use squared
          radius rather than the radius itself to avoid an unnecessary `sqrt`, which
          may introduce gradient singularities. The non-negativity of squared radius
          is only enforced in debug mode.
        distortion_coefficient: A `scalar` or a tensor of shape `[A1, ..., An]`,
          which contains the distortion coefficients of each image.
        name: A name for this op. Defaults to
          "quadratic_radial_distortion_distortion_factor".
  
      Returns:
        distortion_factor: A tensor of shape `[A1, ..., An, H, W]`, the correction
          factor that should multiply the projective coordinates `(x/z)` and `(y/z)`
          to apply the distortion.
        overflow_mask: A boolean tensor of shape `[A1, ..., An, H, W]`, `True` where
          `squared_radius` is beyond the range where the distortion function is
          monotonically increasing. Wherever `overflow_mask` is True,
          `distortion_factor`'s value is meaningless.
      """
      with tf.name_scope(
          name,
      ):
          squared_radius = tf.convert_to_tensor(value=squared_radius)
          distortion_coefficient = tf.convert_to_tensor(
              value=distortion_coefficient
          )
  
          if distortion_coefficient.shape.ndims == 0:
              distortion_coefficient = tf.expand_dims(
                  distortion_coefficient, axis=0
              )
          shape.check_static(
              tensor=squared_radius,
              tensor_name="squared_radius",
              has_rank_greater_than=1,
          )
          shape.compare_batch_dimensions(
              tensors=(squared_radius, distortion_coefficient),
              tensor_names=("squared_radius", "distortion_coefficient"),
              last_axes=(-3, -1),
              broadcast_compatible=True,
          )
          squared_radius = asserts.assert_all_above(
              squared_radius, 0.0, open_bound=False
          )
          distortion_coefficient = tf.expand_dims(
              distortion_coefficient, axis=-1
          )
          distortion_coefficient = tf.expand_dims(
              distortion_coefficient, axis=-1
          )
          distortion_coefficient_times_squared_radius = (
              distortion_coefficient * squared_radius
          )
          distortion_factor_ = (
              1.0 + distortion_coefficient_times_squared_radius
          )
          # This condition needs to hold for the distortion to be monotomnically
          # increasing, as can be derived by differentiating it.
          overflow_mask = tf.less(
              1.0 + 3.0 * distortion_coefficient_times_squared_radius,
              0.0,
          )
          return distortion_factor_, overflow_mask
  
file_path: graphics/tensorflow_graphics/rendering/camera/quadratic_radial_distortion.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Tuple
  from six.moves import range
  import tensorflow
  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 1 for calling a global function with example usage: distortion_factor(squared_radius, distortion_coefficient, name) and returns: distortion_factor_,  overflow_mask