code: def add_gaussian_noise(
      image: tf.Tensor,
      noise_magnitude: tf.Tensor,
      use_additive_noise: bool,
      rng: int,
      denoise_configs: ml_collections.ConfigDict,
      dtype: tf.DType = tf.float32,
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Add gaussian noise to the given image.
  
      Args:
        image: A single image,must be in 0-1 range.
        noise_magnitude: Amount of noise to be added to the image.
        use_additive_noise: Whether to use a simple additive noise formulation.
        rng: Seed for sampling the noise.
        denoise_configs: Configurations for the denoising process.
        dtype: Data type of the image.
  
      Returns:
        The corrupted image and the noise.
      """
      del rng
  
      h, w, c = image.shape
      if denoise_configs.use_coarse_noise:
          fh, fw = denoise_configs.patch_size
          gh, gw = h // fh, w // fw
  
          noise = tf.random.normal(
              (gh, gw, c),
              mean=0.0,
              stddev=1.0,
              dtype=dtype,
              seed=None,
              name=None,
          )
          # upsample the noise to the original image resolution
          noise = tf.image.resize(noise, [h, w], method="nearest")
      else:
          noise = tf.random.normal(
              (h, w, c),
              mean=0.0,
              stddev=1.0,
              dtype=dtype,
              seed=None,
              name=None,
          )
  
      if use_additive_noise:
          logging.info("Using simple additive noise formulation.")
          noise = noise_magnitude * noise
          noised_image = image + noise
          if denoise_configs.clip_values:
              logging.info("Clipping values to be between 0 and 1.")
              noised_image = tf.clip_by_value(noised_image, 0.0, 1.0)
              noise = noised_image - image
      else:
          logging.info("Using ddpm noise and image scaling formulation")
          scale_img = tf.sqrt(noise_magnitude) * image
          scale_noise = (
              (tf.sqrt(1 - noise_magnitude) * noise)
              - tf.sqrt(noise_magnitude)
              + 1.0
          ) / 2
          noised_image = scale_img + scale_noise
          if denoise_configs.clip_values:
              logging.info("Clipping values to be between 0 and 1.")
              noised_image = tf.clip_by_value(noised_image, 0.0, 1.0)
  
          if noise_magnitude == 1.0:
              noise = noise * 0.0
      return noised_image, noise
  
file_path: scenic/scenic/projects/robust_segvit/datasets/denoise_utils.py
imports: from typing import Tuple, Optional
  from absl import logging
  import ml_collections
  import tensorflow
label_desc: Use image node_id 4 for calling a global function with example usage: add_gaussian_noise(image, noise_magnitude, use_additive_noise, rng, denoise_configs, dtype) and returns: noised_image,  noise