code: def test_images(self, make_lib_fail, dtypes, channels):
      dtype, np_dtype = dtypes
      with make_lib_fail() as failing_lib:
          if _unsupported_images_for_pil(np_dtype, failing_lib):
              return
          img = randint(256, size=(128, 100, channels), dtype=np_dtype)
          img_other_shape = randint(
              256, size=(64, 200, channels), dtype=np_dtype
          )
  
          filename = {
              np.uint8: {
                  1: "6pixels_grayscale.png",
                  3: "6pixels.png",
                  4: "6pixels_4chan.png",
              },
              np.uint16: {
                  1: "6pixels_grayscale_16bit.png",
                  3: "6pixels_16bit.png",
                  4: "6pixels_16bit_4chan.png",
              },
          }[np_dtype][channels]
  
          img_file_path = os.path.join(
              os.path.dirname(__file__),
              "../../testing/test_data",
              filename,
          )
          with tf.io.gfile.GFile(img_file_path, "rb") as f:
              img_byte_content = f.read()
          img_file_expected_content = np.array(
              [
                  [
                      [0, 255, 0, 255],
                      [255, 0, 0, 255],
                      [255, 0, 255, 255],
                  ],
                  [
                      [0, 0, 255, 255],
                      [255, 255, 0, 255],
                      [126, 127, 128, 255],
                  ],
              ],
              dtype=np_dtype,
          )[
              :, :, :channels
          ]  # Truncate (h, w, 4) -> (h, w, c)
          if dtype == np.uint16 or dtype == tf.uint16:
              img_file_expected_content *= 257  # Scale int16 images
  
          numpy_array = testing.FeatureExpectationItem(
              value=img,
              expected=img,
              expected_np=img,
          )
          file_path_as_string = testing.FeatureExpectationItem(
              value=img_file_path,
              expected=img_file_expected_content,
              expected_np=img_file_expected_content,
          )
          file_path_as_path = testing.FeatureExpectationItem(
              value=pathlib.Path(img_file_path),
              expected=img_file_expected_content,
              expected_np=img_file_expected_content,
          )
          images_bytes = testing.FeatureExpectationItem(
              value=img_byte_content,
              expected=img_file_expected_content,
              expected_np=img_file_expected_content,
          )
          img_shape_can_be_dynamic = testing.FeatureExpectationItem(
              value=img_other_shape,
              expected=img_other_shape,
              expected_np=img_other_shape,
          )
          invalid_type = testing.FeatureExpectationItem(
              value=randint(
                  256, size=(128, 128, channels), dtype=np.uint32
              ),
              raise_cls=ValueError,
              raise_cls_np=ValueError,
              raise_msg="dtype should be",
          )
          tests = [
              numpy_array,
              file_path_as_string,
              file_path_as_path,
              images_bytes,
              img_shape_can_be_dynamic,
              invalid_type,
          ]
          # PIL doesn't support 16-bit images.
          if (
              failing_lib != LibWithImportError.PIL
          ) and np_dtype != np.uint16:
              tests.append(
                  testing.FeatureExpectationItem(
                      value=PIL.Image.open(img_file_path),
                      expected=img_file_expected_content,
                      expected_np=img_file_expected_content,
                  )
              )
          self.assertFeature(
              feature=features_lib.Image(
                  shape=(None, None, channels), dtype=dtype
              ),
              shape=(None, None, channels),
              dtype=dtype,
              tests=tests,
              test_attributes=dict(
                  _encoding_format=None,
                  _use_colormap=False,
              ),
          )
  
imports: import contextlib
  import enum
  import os
  import pathlib
  from typing import Optional, Type
  from absl.testing import parameterized
  import numpy
  import PIL
  import pytest
  import tensorflow
  import tensorflow_datasets
  from tensorflow_datasets import testing
  from tensorflow_datasets.core import features
label_desc: Use image node_id 1 for calling the ImageFeatureTest obj's underlying member method code with example usage: obj.test_images(make_lib_fail, dtypes, channels) without return types