code: def best_convolution(bin_template, bin_image,
                       tollerance=0.5, overlap_table=OVERLAP_TABLE):
      
  
      template_sum = numpy.count_nonzero(bin_template)
      th, tw = bin_template.shape
      ih, iw = bin_image.shape
      if template_sum == 0 or th == 0 or tw == 0:
          # If we don't have a template
          return []
      if th > ih or tw > iw:
          # If the template is bigger than the image
          return []
  
      # How many cells can we split the image into?
      max_vert_cells = ih // th
      max_hor_cells = iw // th
  
      # Try to work out how many times we can stack the image
      usable_factors = {n: factors for n, factors in overlap_table.iteritems()
                        if ((template_sum + 1) ** (n)) < ACCURACY_LIMIT}
      overlap_options = [(factor, n // factor)
                         for n, factors in usable_factors.iteritems()
                         for factor in factors
                         if (factor <= max_vert_cells and
                             n // factor <= max_hor_cells)]
      if not overlap_options:
          # We can't stack the image
          return convolution(bin_template, bin_image, tollerance=tollerance)
      best_overlap = min(overlap_options,
                         key=lambda x: ((ih // x[0] + th) * (iw // x[1] + tw)))
      return overlapped_convolution(bin_template, bin_image,
                                    tollerance=tollerance, splits=best_overlap)
docs: Selects and applies the best convolution method to find template in image.
  
      Returns a list of matches in (width, height, x offset, y offset)
      format (where the x and y offsets are from the top left corner).
  
      As the images are binary images, we can utilise the extra bit space in the
      float64's by cutting the image into tiles and stacking them into variable
      grayscale values.
  
      This allows converting a sparse binary image into a dense(r) grayscale one.