code: def filter_ocr_image(
      page: PageContext, image: Image.Image
  ) -> Image.Image:
      """Filter the image before OCR.
  
      Tesseract cannot handle images with more than 32767 pixels in either axis,
      or more than 2**31 bytes. This function resizes the image to fit within
      those limits.
      """
      threshold = min(page.options.tesseract_downsample_above, 32767)
  
      options = page.options
      if options.tesseract_downsample_large_images:
          size = calculate_downsample(
              image,
              max_size=(threshold, threshold),
              max_bytes=(2**31) - 1,
          )
          image = downsample_image(image, size)
      return image
  
imports: from __future__ import annotations
  import logging
  import os
  from PIL import Image
  from ocrmypdf import hookimpl
  from ocrmypdf._exec import tesseract
  from ocrmypdf._jobcontext import PageContext
  from ocrmypdf.cli import numeric, str_to_int
  from ocrmypdf.helpers import clamp
  from ocrmypdf.imageops import calculate_downsample, downsample_image
  from ocrmypdf.pluginspec import OcrEngine
  from ocrmypdf.subprocess import check_external_program
label_desc: Use image node_id 4 for calling a global function with example usage: filter_ocr_image(page, image) and returns: image