code: def compute_mean_from_dir(
      DIR, channels, per_channel_subtraction=True, recursive=True
  ) -> Union[tuple, None]:
      """
      Computes mean per channel
      Mean must be computed ONLY on the train set
      """
      if not exists(DIR):
          raise ValueError("The specified directory does not exist")
  
      image_list: list = list_images(
          DIR, recursive=recursive, use_fullpath=True, verbose=0
      )
  
      if len(image_list) == 0:
          raise ValueError(f"No images found at {DIR}")
  
      if channels == 3:
          rMean, gMean, bMean = 0.0, 0.0, 0.0
      if channels == 1:
          bgrMean: float = 0.0
  
      count: int = 0
  
      for tens_filepath in image_list:
          count += 1
          tens = imread(tens_filepath, rgb=True)
  
          if channels == 3:
              b, g, r = cv.mean(tens.astype("float32"))[:3]
              rMean += r
              bMean += b
              gMean += g
  
          if channels == 1:
              bgrMean += np.mean(tens.astype("float32"))
  
      # Computing average mean
      if channels == 3:
          rMean /= count
          bMean /= count
          gMean /= count
  
          if per_channel_subtraction:
              return rMean, bMean, gMean
          else:
              mean_of_means = (rMean + bMean + gMean) / 3
              return mean_of_means, mean_of_means, mean_of_means
  
      if channels == 1:
          bgrMean /= count
          return tuple([bgrMean])
  
      return None
  
file_path: caer/caer/preprocessing/mean_subtraction.py
imports: from .._internal import _check_mean_sub_values
  from ..path import exists, list_images
  from ..io import imread
  from ..coreten import Tensor
  from ..annotations import Tuple, List, Union
  import numpy
  import cv2
label_desc: Use image node_id 1 for calling a global function with example usage: compute_mean_from_dir(DIR, channels, per_channel_subtraction, recursive) and returns: None, tuple, rMean,  bMean,  gMean, mean_of_means,  mean_of_means,  mean_of_means