class_docstr: Check if the average image brightness (or bbox location if applicable) is similar between train and test set.
  
  The check computes the average grayscale image per dataset (train and test) and compares the resulting images.
  Additionally, in case of an object detection task, the check will compare the average locations of the bounding
  boxes between the datasets.
  
  Parameters
  ----------
  {additional_check_init_params:2*indent}
class_docstr_tok: ["Check","if","the","average","image","brightness","(","or","bbox","location","if","applicable",")","is","similar","between","train","and","test","set",".","The","check","computes","the","average","grayscale","image","per","dataset","(","train","and","test",")","and","compares","the","resulting","images",".","Additionally",",","in","case","of","an","object","detection","task",",","the","check","will","compare","the","average","locations","of","the","bounding","boxes","between","the","datasets",".","Parameters","--","--","--","--","--","{","additional_check_init_params:2","*","indent","}"]
docstr: Sum all images in batch to one grayscale image of shape target_shape.
  
  Parameters
  ----------
  batch: np.ndarray
      batch of images.
  
  Returns
  -------
  np.ndarray
      summed image.
docstr_tok: ["Sum","all","images","in","batch","to","one","grayscale","image","of","shape","target_shape",".","Parameters","--","--","--","--","--","batch",":","np.ndarray","batch","of","images",".","Returns","--","--","--","-","np.ndarray","summed","image","."]
code: def _grayscale_sum_image(
      self, batch: Iterable[np.ndarray]
  ) -> np.ndarray:
      """Sum all images in batch to one grayscale image of shape target_shape.
  
      Parameters
      ----------
      batch: np.ndarray
          batch of images.
  
      Returns
      -------
      np.ndarray
          summed image.
      """
      summed_image = None
  
      # Iterate over all images in batch, using the first image as the target shape if target_shape is None.
      # All subsequent images will be resized to the target shape and their gray values will be added to the
      # summed image.
      for img in batch:
          # Cast to grayscale
          if img.shape[2] == 1:
              resized_img = img
          elif img.shape[2] == 3:
              resized_img = cv2.cvtColor(
                  img.astype("uint8"), cv2.COLOR_RGB2GRAY
              )
          else:
              raise NotImplementedError(
                  "Images must be RGB or grayscale"
              )
  
          # reshape to one shape
          if self._shape is None:
              self._shape = resized_img.shape[:2][::-1]
          resized_img = cv2.resize(
              resized_img.astype("uint8"),
              self._shape,
              interpolation=cv2.INTER_AREA,
          )
  
          # sum images
          if summed_image is None:
              summed_image = resized_img.squeeze().astype(np.int64)
          else:
              summed_image += resized_img.squeeze().astype(np.int64)
  
      return summed_image
  
imports: from collections import defaultdict
  from typing import Iterable, List, Optional, Tuple
  import cv2
  import numpy
  import plotly.graph_objs
  from plotly.subplots import make_subplots
  from deepchecks.core import CheckResult, DatasetKind
  from deepchecks.vision._shared_docs import docstrings
  from deepchecks.vision.base_checks import TrainTestCheck
  from deepchecks.vision.context import Context
  from deepchecks.vision.utils.image_functions import apply_heatmap_image_properties, numpy_grayscale_to_heatmap_figure
  from deepchecks.vision.vision_data import TaskType
  from deepchecks.vision.vision_data.batch_wrapper import BatchWrapper
label_desc: Use image node_id 9 for calling the HeatmapComparison obj's underlying member method code with example usage: obj._grayscale_sum_image(batch) and returns: summed_image