code: def assert_compare_images(a, b, max_average_diff, max_diff=255):
      assert (
          a.mode == b.mode
      ), f"got mode {repr(a.mode)}, expected {repr(b.mode)}"
      assert (
          a.size == b.size
      ), f"got size {repr(a.size)}, expected {repr(b.size)}"
  
      a, b = convert_to_comparable(a, b)
  
      bands = ImageMode.getmode(a.mode).bands
      for band, ach, bch in zip(bands, a.split(), b.split()):
          ch_diff = ImageMath.eval(
              "convert(abs(a - b), 'L')", a=ach, b=bch
          )
          ch_hist = ch_diff.histogram()
  
          average_diff = sum(
              i * num for i, num in enumerate(ch_hist)
          ) / (a.size[0] * a.size[1])
          msg = (
              f"average pixel value difference {average_diff:.4f} > "
              f"expected {max_average_diff:.4f} for '{band}' band"
          )
          assert max_average_diff >= average_diff, msg
  
          last_diff = [i for i, num in enumerate(ch_hist) if num > 0][
              -1
          ]
          assert max_diff >= last_diff, (
              f"max pixel value difference {last_diff} > expected {max_diff} "
              f"for '{band}' band"
          )
  
imports: from __future__ import annotations
  import pytest
  from PIL import Image, ImageMath, ImageMode
  from .helper import convert_to_comparable, skip_unless_feature
label_desc: Use image node_id 9 for calling a global function with example usage: assert_compare_images(a, b, max_average_diff, max_diff) without return types