code: def extract_ocr_candidates(
      image,
      gradient_size=3,
      closing_size=10,
      minimum_area=100,
      minimum_aspect_ratio=2,
  ):
      gray_image = skimage.color.rgb2gray(image)
      gradient_image = skimage.filters.rank.gradient(
          gray_image, skimage.morphology.disk(gradient_size)
      )
      bw_image = gradient_image > skimage.filters.threshold_otsu(
          gradient_image
      )
      bw_image = skimage.morphology.closing(
          bw_image, skimage.morphology.rectangle(1, closing_size)
      )
      label_image = skimage.measure.label(bw_image)
  
      regions = skimage.measure.regionprops(label_image)
  
      text_regions = list()
  
      for region in regions:
          if region.area > minimum_area:
              y0, x0, y1, x1 = region.bbox
              region_image = bw_image[y0:y1, x0:x1]
  
              aspect_ratio = (
                  region_image.shape[1] / region_image.shape[0]
              )
  
              black_pixel_count = region_image[region_image == 0].size
              white_pixel_count = region_image[region_image == 1].size
  
              if (
                  aspect_ratio >= minimum_aspect_ratio
                  and white_pixel_count > black_pixel_count
                  and y1 - y0 >= 8
              ):
                  text_regions.append(region.bbox)
  
      ocr_candidates = list()
  
      for text_region in text_regions:
          ocr_candidates.append(
              gray_image[
                  text_region[0] : text_region[2],
                  text_region[1] : text_region[3],
              ]
          )
  
      return ocr_candidates, text_regions
  
file_path: SerpentAI/serpent/ocr.py
imports: import pathlib
  import shutil
  import skimage.color
  import skimage.segmentation
  import skimage.filters
  import skimage.morphology
  import skimage.util
  import skimage.transform
  import skimage.measure
  import skimage.io
  import pytesseract
  from PIL import Image
  from serpent.utilities import is_windows
label_desc: Use image node_id 4 for calling a global function with example usage: extract_ocr_candidates(image, gradient_size, closing_size, minimum_area, minimum_aspect_ratio) and returns: ocr_candidates,  text_regions