1

I am trying to find a smaller image in a larger image. I have it done using PIL, but I am looking for ways to speed it up so I am currently looking for some numpy solutions. So far I have gotten to: loading both RGB images to np.arrays

rows, cols = np.where(np.all(haystack == needle[0,0], axis=-1))
for row, col in zip(rows, cols):
   if row+h > H or col+w > W: continue
   local_haystack = haystack[row:row+h, col:col+w].copy()

And this is where I am stuck, I have tried np.count_nonzeros, np.sum etc. but the problem seems to be, that it counts any color like it would be a flattened array instead of a tuple. So instead of counting 1 for (255, 255, 255) it counts 3 which makes me miss the needle

emceef
  • 11
  • 3
  • Does [this question](https://stackoverflow.com/questions/7853628/how-do-i-find-an-image-contained-within-an-image) help? – orlp Feb 08 '21 at 00:27
  • I know opencv, but unfortunately its slower than my current method with PIL loading and comparing pixel by pixel. I've given up on the numpy method, all the ways I found to find the needle turned out to be 50-100% slower than my current method – emceef Feb 08 '21 at 21:48

0 Answers0