code: def augment_contrast(
      data_sample: np.ndarray,
      contrast_range: Union[
          Tuple[float, float], Callable[[], float]
      ] = (0.75, 1.25),
      preserve_range: bool = True,
      per_channel: bool = True,
      p_per_channel: float = 1,
  ) -> np.ndarray:
      if not per_channel:
          if callable(contrast_range):
              factor = contrast_range()
          else:
              if np.random.random() < 0.5 and contrast_range[0] < 1:
                  factor = np.random.uniform(contrast_range[0], 1)
              else:
                  factor = np.random.uniform(
                      max(contrast_range[0], 1), contrast_range[1]
                  )
  
          for c in range(data_sample.shape[0]):
              if np.random.uniform() < p_per_channel:
                  mn = data_sample[c].mean()
                  if preserve_range:
                      minm = data_sample[c].min()
                      maxm = data_sample[c].max()
  
                  data_sample[c] = (data_sample[c] - mn) * factor + mn
  
                  if preserve_range:
                      data_sample[c][data_sample[c] < minm] = minm
                      data_sample[c][data_sample[c] > maxm] = maxm
      else:
          for c in range(data_sample.shape[0]):
              if np.random.uniform() < p_per_channel:
                  if callable(contrast_range):
                      factor = contrast_range()
                  else:
                      if (
                          np.random.random() < 0.5
                          and contrast_range[0] < 1
                      ):
                          factor = np.random.uniform(
                              contrast_range[0], 1
                          )
                      else:
                          factor = np.random.uniform(
                              max(contrast_range[0], 1),
                              contrast_range[1],
                          )
  
                  mn = data_sample[c].mean()
                  if preserve_range:
                      minm = data_sample[c].min()
                      maxm = data_sample[c].max()
  
                  data_sample[c] = (data_sample[c] - mn) * factor + mn
  
                  if preserve_range:
                      data_sample[c][data_sample[c] < minm] = minm
                      data_sample[c][data_sample[c] > maxm] = maxm
      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 13 for calling a global function with example usage: augment_contrast(data_sample, contrast_range, preserve_range, per_channel, p_per_channel) and returns: data_sample