class_docstr: Resizes images, re-compresses them in JPEG and yields the result.
class_docstr_tok: ["Resizes","images",",","re-compresses","them","in","JPEG","and","yields","the","result","."]
code: def process(self, element):
      filename, content = element
      try:
          image = cv2.imdecode(
              np.frombuffer(content, dtype=np.uint8), flags=3
          )
      except:
          logging.info(
              "Exception raised while decoding image %s", filename
          )
          raise
      if image is None:
          self._images_failed.inc()
          logging.info("Image %s could not be decoded", filename)
      else:
          # GIF images contain a single frame.
          if len(image.shape) == 4:  # rank=4 -> rank=3
              image = image.reshape(image.shape[1:])
          # Get image height and width.
          height, width, _ = image.shape
          actual_pixels = height * width
          # If necessary, resize the image to have at most self._target_pixels,
          # keeping the aspect ratio.
          if (
              self._target_pixels
              and actual_pixels > self._target_pixels
          ):
              factor = np.sqrt(self._target_pixels / actual_pixels)
              image = cv2.resize(
                  image, dsize=None, fx=factor, fy=factor
              )
          # Encode the image with quality=72 and store it in a BytesIO object.
          _, buff = cv2.imencode(".jpg", image, self._jpeg_quality)
          yield filename, io.BytesIO(buff.tobytes())
  
imports: import collections
  import csv
  import io
  import json
  import os
  from absl import logging
  import numpy
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 2 for calling the ProcessImageFn obj's underlying member method code with example usage: obj.process(element) without return types