code: def get_maximum_uniform_contour(image, fontsize, margin=0):
      """Get the largest possible contour of light or
      dark area in an image.
  
      Args:
          image: The image in which to find a contiguous area.
          fontsize: The fontsize for text. Will be used for blurring
              and for determining useful areas.
          margin: The minimum margin required around the image.
  
      Returns:
          A (contour, isDark) tuple. If no contour is found, both
          entries will be None.
      """
      if margin > 0:
          image = image[margin:-margin, margin:-margin]
      gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
      blurred = cv2.blur(src=gray, ksize=(fontsize // 2, fontsize // 2))
      _, threshold = cv2.threshold(
          src=blurred,
          thresh=255 / 2,
          maxval=255,
          type=cv2.THRESH_BINARY,
      )
      contoursDark = cv2.findContours(
          255 - threshold,
          mode=cv2.RETR_TREE,
          method=cv2.CHAIN_APPROX_SIMPLE,
      )[-2]
      contoursLight = cv2.findContours(
          threshold, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_SIMPLE
      )[-2]
      areasDark = list(map(cv2.contourArea, contoursDark))
      areasLight = list(map(cv2.contourArea, contoursLight))
      maxDarkArea = max(areasDark) if areasDark else 0
      maxLightArea = max(areasLight) if areasLight else 0
  
      if max(maxDarkArea, maxLightArea) < (4 * fontsize) ** 2:
          return None, None
  
      contour = None
      isDark = None
      if areasDark and (not areasLight or maxDarkArea >= maxLightArea):
          contour = contoursDark[np.argmax(areasDark)]
          isDark = True
      else:
          contour = contoursLight[np.argmax(areasLight)]
          isDark = False
      if contour is not None:
          contour += margin
      return contour, isDark
  
imports: import os
  import math
  import glob
  import typing
  import random
  import zipfile
  import string
  import itertools
  import cv2
  import tqdm
  import numpy
  import essential_generators
  import PIL.Image
  import PIL.ImageDraw
  import PIL.ImageFont
  import fontTools.ttLib
  from .None import tools
label_desc: Use image node_id 2 for calling a global function with example usage: get_maximum_uniform_contour(image, fontsize, margin) and returns: contour,  isDark, None,  None