code: def test_imresize_many_images():
      interpolations = [
          None,
          "nearest",
          "linear",
          "area",
          "cubic",
          cv2.INTER_NEAREST,
          cv2.INTER_LINEAR,
          cv2.INTER_AREA,
          cv2.INTER_CUBIC,
      ]
  
      for c in [1, 3]:
          image1 = np.zeros((16, 16, c), dtype=np.uint8) + 255
          image2 = np.zeros((16, 16, c), dtype=np.uint8)
          image3 = np.pad(
              np.zeros((8, 8, c), dtype=np.uint8) + 255,
              ((4, 4), (4, 4), (0, 0)),
              mode="constant",
              constant_values=0,
          )
  
          image1_small = np.zeros((8, 8, c), dtype=np.uint8) + 255
          image2_small = np.zeros((8, 8, c), dtype=np.uint8)
          image3_small = np.pad(
              np.zeros((4, 4, c), dtype=np.uint8) + 255,
              ((2, 2), (2, 2), (0, 0)),
              mode="constant",
              constant_values=0,
          )
  
          image1_large = np.zeros((32, 32, c), dtype=np.uint8) + 255
          image2_large = np.zeros((32, 32, c), dtype=np.uint8)
          image3_large = np.pad(
              np.zeros((16, 16, c), dtype=np.uint8) + 255,
              ((8, 8), (8, 8), (0, 0)),
              mode="constant",
              constant_values=0,
          )
  
          images = np.uint8([image1, image2, image3])
          images_small = np.uint8(
              [image1_small, image2_small, image3_small]
          )
          images_large = np.uint8(
              [image1_large, image2_large, image3_large]
          )
  
          for images_this_iter in [
              images,
              list(images),
          ]:  # test for ndarray and list(ndarray) input
              for interpolation in interpolations:
                  images_same_observed = ia.imresize_many_images(
                      images_this_iter,
                      (16, 16),
                      interpolation=interpolation,
                  )
                  for image_expected, image_observed in zip(
                      images_this_iter, images_same_observed
                  ):
                      diff = np.abs(
                          image_expected.astype(np.int32)
                          - image_observed.astype(np.int32)
                      )
                      assert np.sum(diff) == 0
  
              for interpolation in interpolations:
                  images_small_observed = ia.imresize_many_images(
                      images_this_iter,
                      (8, 8),
                      interpolation=interpolation,
                  )
                  for image_expected, image_observed in zip(
                      images_small, images_small_observed
                  ):
                      diff = np.abs(
                          image_expected.astype(np.int32)
                          - image_observed.astype(np.int32)
                      )
                      diff_fraction = np.sum(diff) / (
                          image_observed.size * 255
                      )
                      assert diff_fraction < 0.5
  
              for interpolation in interpolations:
                  images_large_observed = ia.imresize_many_images(
                      images_this_iter,
                      (32, 32),
                      interpolation=interpolation,
                  )
                  for image_expected, image_observed in zip(
                      images_large, images_large_observed
                  ):
                      diff = np.abs(
                          image_expected.astype(np.int32)
                          - image_observed.astype(np.int32)
                      )
                      diff_fraction = np.sum(diff) / (
                          image_observed.size * 255
                      )
                      assert diff_fraction < 0.5
  
      # test size given as single int
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, 8)
      assert observed.shape == (1, 8, 8, 3)
  
      # test size given as single float
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, 2.0)
      assert observed.shape == (1, 8, 8, 3)
  
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, 0.5)
      assert observed.shape == (1, 2, 2, 3)
  
      # test size given as (float, float)
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, (2.0, 2.0))
      assert observed.shape == (1, 8, 8, 3)
  
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, (0.5, 0.5))
      assert observed.shape == (1, 2, 2, 3)
  
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, (2.0, 0.5))
      assert observed.shape == (1, 8, 2, 3)
  
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, (0.5, 2.0))
      assert observed.shape == (1, 2, 8, 3)
  
      # test size given as int+float or float+int
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, (11, 2.0))
      assert observed.shape == (1, 11, 8, 3)
  
      images = np.zeros((1, 4, 4, 3), dtype=np.uint8)
      observed = ia.imresize_many_images(images, (2.0, 11))
      assert observed.shape == (1, 8, 11, 3)
  
      # test no channels
      images = np.zeros((1, 4, 4), dtype=np.uint8)
      images_rs = ia.imresize_many_images(images, (2, 2))
      assert images_rs.shape == (1, 2, 2)
  
      images = [np.zeros((4, 4), dtype=np.uint8)]
      images_rs = ia.imresize_many_images(images, (2, 2))
      assert isinstance(images_rs, list)
      assert images_rs[0].shape == (2, 2)
  
      # test len 0 input
      observed = ia.imresize_many_images(
          np.zeros((0, 8, 8, 3), dtype=np.uint8), (4, 4)
      )
      assert ia.is_np_array(observed)
      assert observed.dtype.type == np.uint8
      assert len(observed) == 0
  
      observed = ia.imresize_many_images([], (4, 4))
      assert isinstance(observed, list)
      assert len(observed) == 0
  
      # test images with zero height/width
      shapes = [(0, 4, 3), (4, 0, 3), (0, 0, 3)]
      for shape in shapes:
          images = [np.zeros(shape, dtype=np.uint8)]
          got_exception = False
          try:
              _ = ia.imresize_many_images(images, sizes=(2, 2))
          except Exception as exc:
              assert (
                  "Cannot resize images, because at least one image has a height "
                  "and/or width and/or number of channels of zero."
                  in str(exc)
              )
              got_exception = True
          assert got_exception
  
      # test invalid sizes
      sizes_all = [(-1, 2)]
      sizes_all = (
          sizes_all
          + [(float(a), b) for a, b in sizes_all]
          + [(a, float(b)) for a, b in sizes_all]
          + [(float(a), float(b)) for a, b in sizes_all]
          + [(-a, -b) for a, b in sizes_all]
          + [(-float(a), -b) for a, b in sizes_all]
          + [(-a, -float(b)) for a, b in sizes_all]
          + [(-float(a), -float(b)) for a, b in sizes_all]
      )
      sizes_all = sizes_all + [(b, a) for a, b in sizes_all]
      sizes_all = sizes_all + [-1.0, -1]
      for sizes in sizes_all:
          images = [np.zeros((4, 4, 3), dtype=np.uint8)]
          got_exception = False
          try:
              _ = ia.imresize_many_images(images, sizes=sizes)
          except Exception as exc:
              assert ">= 0" in str(exc)
              got_exception = True
          assert got_exception
  
      # test list input but all with same shape
      images = [np.zeros((8, 8, 3), dtype=np.uint8) for _ in range(2)]
      observed = ia.imresize_many_images(images, (4, 4))
      assert isinstance(observed, list)
      assert all([image.shape == (4, 4, 3) for image in observed])
      assert all([image.dtype.type == np.uint8 for image in observed])
  
      # test multiple shapes
      images = [
          np.zeros((8, 8, 3), dtype=np.uint8),
          np.zeros((4, 4), dtype=np.uint8),
      ]
      observed = ia.imresize_many_images(images, (4, 4))
      assert observed[0].shape == (4, 4, 3)
      assert observed[1].shape == (4, 4)
      assert observed[0].dtype == np.uint8
      assert observed[1].dtype == np.uint8
  
      ###################
      # test other dtypes
      ###################
      # interpolation="nearest"
      image = np.zeros((4, 4), dtype=bool)
      image[1, :] = True
      image[2, :] = True
      expected = np.zeros((3, 3), dtype=bool)
      expected[1, :] = True
      expected[2, :] = True
      image_rs = ia.imresize_many_images(
          [image], (3, 3), interpolation="nearest"
      )[0]
      assert image_rs.dtype.type == image.dtype.type
      assert np.all(image_rs == expected)
  
      for dtype in [np.uint8, np.uint16, np.int8, np.int16, np.int32]:
          (
              min_value,
              center_value,
              max_value,
          ) = iadt.get_value_range_of_dtype(dtype)
          for value in [min_value, max_value]:
              image = np.zeros((4, 4), dtype=dtype)
              image[1, :] = value
              image[2, :] = value
              expected = np.zeros((3, 3), dtype=dtype)
              expected[1, :] = value
              expected[2, :] = value
              image_rs = ia.imresize_many_images(
                  [image], (3, 3), interpolation="nearest"
              )[0]
              assert image_rs.dtype.type == dtype
              assert np.all(image_rs == expected)
  
      for dtype in [np.float16, np.float32, np.float64]:
          isize = np.dtype(dtype).itemsize
          for value in [
              0.5,
              -0.5,
              1.0,
              -1.0,
              10.0,
              -10.0,
              -(1000 ** (isize - 1)),
              1000 * (isize + 1),
          ]:
              image = np.zeros((4, 4), dtype=dtype)
              image[1, :] = value
              image[2, :] = value
              expected = np.zeros((3, 3), dtype=dtype)
              expected[1, :] = value
              expected[2, :] = value
              image_rs = ia.imresize_many_images(
                  [image], (3, 3), interpolation="nearest"
              )[0]
              assert image_rs.dtype.type == dtype
              assert np.allclose(image_rs, expected, rtol=0, atol=1e-8)
  
      # other interpolations
      for ip in ["linear", "cubic", "area"]:
          mask = np.zeros((4, 4), dtype=np.uint8)
          mask[1, :] = 255
          mask[2, :] = 255
          mask = ia.imresize_many_images(
              [mask], (3, 3), interpolation=ip
          )[0]
          mask = mask.astype(np.float64) / 255.0
  
          image = np.zeros((4, 4), dtype=bool)
          image[1, :] = True
          image[2, :] = True
          expected = mask > 0.5
          image_rs = ia.imresize_many_images(
              [image], (3, 3), interpolation=ip
          )[0]
          assert image_rs.dtype.type == image.dtype.type
          assert np.all(image_rs == expected)
  
          for dtype in [np.uint8, np.uint16, np.int8, np.int16]:
              (
                  min_value,
                  center_value,
                  max_value,
              ) = iadt.get_value_range_of_dtype(dtype)
              dynamic_range = max_value - min_value
              for value in [min_value + 1, max_value - 1]:
                  image = np.zeros((4, 4), dtype=dtype)
                  image[1, :] = value
                  image[2, :] = value
                  expected = np.round(mask * value).astype(dtype)
                  image_rs = ia.imresize_many_images(
                      [image], (3, 3), interpolation=ip
                  )[0]
                  assert image_rs.dtype.type == dtype
                  diff = np.abs(
                      image_rs.astype(np.int64)
                      - expected.astype(np.int64)
                  )
                  assert np.all(diff < 2 * (1 / 255) * dynamic_range)
  
          mask = np.zeros((4, 4), dtype=np.float64)
          mask[1, :] = 1.0
          mask[2, :] = 1.0
          mask = ia.imresize_many_images(
              [mask], (3, 3), interpolation=ip
          )[0]
          mask = mask.astype(np.float64)
  
          for dtype in [np.float16, np.float32, np.float64]:
              isize = np.dtype(dtype).itemsize
  
              for value in [
                  0.5,
                  -0.5,
                  1.0,
                  -1.0,
                  10.0,
                  -10.0,
                  -(1000 ** (isize - 1)),
                  1000 * (isize + 1),
              ]:
                  image = np.zeros((4, 4), dtype=dtype)
                  image[1, :] = value
                  image[2, :] = value
                  expected = (mask * np.float64(value)).astype(dtype)
                  image_rs = ia.imresize_many_images(
                      [image], (3, 3), interpolation=ip
                  )[0]
                  assert image_rs.dtype.type == dtype
                  # Our basis for the expected image is derived from uint8 as that is most likely to work, so we will
                  # have to accept here deviations of around 1/255.
                  atol = (
                      np.float64(1 / 255) * np.abs(np.float64(value))
                      + 1e-8
                  )
                  assert np.allclose(
                      image_rs, expected, rtol=0, atol=atol
                  )
                  # Expect at least one cell to have a difference between observed and expected image of approx. 0,
                  # currently we seem to be able to get away with this despite the above mentioned inaccuracy.
                  assert np.any(
                      np.isclose(image_rs, expected, rtol=0, atol=1e-4)
                  )
  
imports: from __future__ import print_function, division, absolute_import
  import time
  import warnings
  import sys
  import matplotlib
  import numpy
  import six.moves
  import cv2
  import imgaug
  from imgaug import dtypes
  import imgaug.random
  from imgaug.testutils import assertWarns
label_desc: Use image node_id 26 for calling a global function with example usage: test_imresize_many_images() without return types