title: What could cause a Value Error in this short image matching function in Python (using numpy)?
body: <p>I need a Python program I am working on to be able to find an exact, pixel for pixel match of a small image inside a larger one.  I have been using the following function, which is a slightly modified version of some code given in an answer to a question about how to do such image matching right here on Stack Overflow.  See here: <a href="https://stackoverflow.com/questions/29663764/determine-if-an-image-exists-within-a-larger-image-and-if-so-find-it-using-py">Determine if an image exists within a larger image, and if so, find it, using Python</a></p>
  
  <pre><code>def find_image(im, tpl):
      '''finds an exact, pixel for pixel match of tpl inside im, or raises an 
      exception'''
      im = np.atleast_3d(im)
      tpl = np.atleast_3d(tpl)
      H, W, D = im.shape[:3]
      h, w = tpl.shape[:2]
  
      # Integral image and template sum per channel
      sat = im.cumsum(1).cumsum(0)
      tplsum = np.array([tpl[:, :, i].sum() for i in range(D)])
  
      # Calculate lookup table for all the possible windows
      iA, iB, iC, iD = sat[:-h, :-w], sat[:-h, w:], sat[h:, :-w], sat[h:, w:] 
      lookup = iD - iB - iC + iA
      # Possible matches
      possible_match = np.where(np.logical_and(*[lookup[..., i] == tplsum[i] for i in range(D)]))
  
      # Find exact match
      for y, x in zip(*possible_match):
          if np.all(im[y+1:y+h+1, x+1:x+w+1] == tpl):
              return (y+1, x+1)
  
      raise Exception("Image not found")
  </code></pre>
  
  <p>This has been working extremely well in most cases, but in one case, which happens to be very important, I got the following error.</p>
  
  <p><code>possible_match = np.where(np.logical_and(*[lookup[..., i] == tplsum[i] for i in range(D)]))</code></p>
  
  <p><code>ValueError: invalid number of arguments</code></p>
  
  <p>I can't figure out what is causing this problem, or how to fix it.  Any help would be much appreciated.</p>