code: def mock_raw_image(
      x_dim=1024,
      y_dim=1024,
      num_channels=3,
      output_path=None,
      write_image=True,
  ):
      """Generate random `x_dim` by `y_dim`, optionally to `output_path`.
  
      Args:
        x_dim: int, the x dimension of generated raw image.
        y_dim: int, the x dimension of generated raw image.
        num_channels: int, number of channels in image.
        output_path: str, path to which to write image.
        write_image: bool, whether to write the image to output_path.
  
      Returns:
        numpy.array: The random `x_dim` by `y_dim` image (i.e. array).
      """
  
      rand_shape = (x_dim, y_dim, num_channels)
  
      if num_channels != 3:
          raise NotImplementedError(
              "mock_raw_image for channels != 3 not yet " "implemented."
          )
  
      img = np.random.random(rand_shape)
      img = np.uint8(img * 255)
  
      if write_image:
          image_obj = allen_brain.PIL_Image()
          pil_img = image_obj.fromarray(img, mode="RGB")
          with tf.gfile.Open(output_path, "w") as f:
              pil_img.save(f, "jpeg")
  
      return img
  
imports: import os
  import shutil
  import tempfile
  import numpy
  from tensor2tensor.data_generators import allen_brain
  from tensor2tensor.models import image_transformer_2d
  from tensor2tensor.utils import contrib
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 1 for calling a global function with example usage: mock_raw_image(x_dim, y_dim, num_channels, output_path, write_image) and returns: img