code: def _load_img(handle, target_dtype=np.float32, size=None, **kwargs):
      """Load image file as numpy array."""
  
      image_pil = PIL.Image.open(handle, **kwargs)
  
      # resize the image to the requested size, if one was specified
      if size is not None:
          if len(size) > 2:
              size = size[:2]
              log.warning(
                  "`_load_img()` received size: {}, trimming to first two dims!".format(
                      size
                  )
              )
          image_pil = image_pil.resize(size, resample=PIL.Image.LANCZOS)
  
      image_array = np.asarray(image_pil)
  
      # remove alpha channel if it contains no information
      # if image_array.shape[-1] > 3 and 'A' not in image_pil.mode:
      # image_array = image_array[..., :-1]
  
      image_dtype = image_array.dtype
      image_max_value = np.iinfo(
          image_dtype
      ).max  # ...for uint8 that's 255, etc.
  
      # using np.divide should avoid an extra copy compared to doing division first
      ndimage = np.divide(
          image_array, image_max_value, dtype=target_dtype
      )
  
      rank = len(ndimage.shape)
      if rank == 3:
          return ndimage
      elif rank == 2:
          return np.repeat(np.expand_dims(ndimage, axis=2), 3, axis=2)
      else:
          message = "Loaded image has more dimensions than expected: {}".format(
              rank
          )
          raise NotImplementedError(message)
  
imports: import io
  import lzma
  import os
  import json
  import logging
  import pickle
  import numpy
  import PIL.Image
  import tensorflow
  from concurrent.futures import ThreadPoolExecutor, as_completed
  from google.protobuf.message import DecodeError
  from lucid.misc.io.reading import read_handle
  from lucid.misc.io.scoping import current_io_scopes, set_io_scopes
  from lucid.misc.io.saving import nullcontext
label_desc: Use image node_id 3 for calling a global function with example usage: _load_img(handle, target_dtype, size) and returns: ndimage, np