code: def augment_gamma(
      data_sample,
      gamma_range=(0.5, 2),
      invert_image=False,
      epsilon=1e-7,
      per_channel=False,
      retain_stats: Union[bool, Callable[[], bool]] = False,
  ):
      if invert_image:
          data_sample = -data_sample
  
      if not per_channel:
          retain_stats_here = (
              retain_stats() if callable(retain_stats) else retain_stats
          )
          if retain_stats_here:
              mn = data_sample.mean()
              sd = data_sample.std()
          if np.random.random() < 0.5 and gamma_range[0] < 1:
              gamma = np.random.uniform(gamma_range[0], 1)
          else:
              gamma = np.random.uniform(
                  max(gamma_range[0], 1), gamma_range[1]
              )
          minm = data_sample.min()
          rnge = data_sample.max() - minm
          data_sample = (
              np.power(
                  ((data_sample - minm) / float(rnge + epsilon)), gamma
              )
              * rnge
              + minm
          )
          if retain_stats_here:
              data_sample = data_sample - data_sample.mean()
              data_sample = (
                  data_sample / (data_sample.std() + 1e-8) * sd
              )
              data_sample = data_sample + mn
      else:
          for c in range(data_sample.shape[0]):
              retain_stats_here = (
                  retain_stats()
                  if callable(retain_stats)
                  else retain_stats
              )
              if retain_stats_here:
                  mn = data_sample[c].mean()
                  sd = data_sample[c].std()
              if np.random.random() < 0.5 and gamma_range[0] < 1:
                  gamma = np.random.uniform(gamma_range[0], 1)
              else:
                  gamma = np.random.uniform(
                      max(gamma_range[0], 1), gamma_range[1]
                  )
              minm = data_sample[c].min()
              rnge = data_sample[c].max() - minm
              data_sample[c] = (
                  np.power(
                      ((data_sample[c] - minm) / float(rnge + epsilon)),
                      gamma,
                  )
                  * float(rnge + epsilon)
                  + minm
              )
              if retain_stats_here:
                  data_sample[c] = (
                      data_sample[c] - data_sample[c].mean()
                  )
                  data_sample[c] = (
                      data_sample[c]
                      / (data_sample[c].std() + 1e-8)
                      * sd
                  )
                  data_sample[c] = data_sample[c] + mn
      if invert_image:
          data_sample = -data_sample
      return data_sample
  
imports: from typing import List, Tuple, Union, Callable
  import collections
  import numbers
  import random
  import numpy
  import scipy
  import scipy.ndimage
  import SimpleITK
  from scipy.ndimage.filters import gaussian_filter, gaussian_gradient_magnitude
  from skimage.transform import resize
label_desc: Use image node_id 15 for calling a global function with example usage: augment_gamma(data_sample, gamma_range, invert_image, epsilon, per_channel, retain_stats) and returns: data_sample