code: def compare_reduce_with_reference(
      im, factor, average_diff=0.4, max_diff=1
  ):
      """Image.reduce() should look very similar to Image.resize(BOX).
  
      A reference image is compiled from a large source area
      and possible last column and last row.
      +-----------+
      |..........c|
      |..........c|
      |..........c|
      |rrrrrrrrrrp|
      +-----------+
      """
      reduced = im.reduce(factor)
  
      if not isinstance(factor, (list, tuple)):
          factor = (factor, factor)
  
      reference = Image.new(im.mode, reduced.size)
      area_size = (im.size[0] // factor[0], im.size[1] // factor[1])
      area_box = (
          0,
          0,
          area_size[0] * factor[0],
          area_size[1] * factor[1],
      )
      area = im.resize(area_size, Image.Resampling.BOX, area_box)
      reference.paste(area, (0, 0))
  
      if area_size[0] < reduced.size[0]:
          assert reduced.size[0] - area_size[0] == 1
          last_column_box = (area_box[2], 0, im.size[0], area_box[3])
          last_column = im.resize(
              (1, area_size[1]), Image.Resampling.BOX, last_column_box
          )
          reference.paste(last_column, (area_size[0], 0))
  
      if area_size[1] < reduced.size[1]:
          assert reduced.size[1] - area_size[1] == 1
          last_row_box = (0, area_box[3], area_box[2], im.size[1])
          last_row = im.resize(
              (area_size[0], 1), Image.Resampling.BOX, last_row_box
          )
          reference.paste(last_row, (0, area_size[1]))
  
      if (
          area_size[0] < reduced.size[0]
          and area_size[1] < reduced.size[1]
      ):
          last_pixel_box = (
              area_box[2],
              area_box[3],
              im.size[0],
              im.size[1],
          )
          last_pixel = im.resize(
              (1, 1), Image.Resampling.BOX, last_pixel_box
          )
          reference.paste(last_pixel, area_size)
  
      assert_compare_images(reduced, reference, average_diff, max_diff)
  
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 8 for calling a global function with example usage: compare_reduce_with_reference(im, factor, average_diff, max_diff) without return types