Search code examples
pythonpython-imaging-library

How to find subimage using the PIL library?


I want to find the sub-image from large image using PIL library. I also want to know the coordinates where it is found ?


Solution

  • import cv2
    import numpy as np
    image = cv2.imread("Large.png")
    template = cv2.imread("small.png")
    result = cv2.matchTemplate(image,template,cv2.TM_CCOEFF_NORMED)
    print np.unravel_index(result.argmax(),result.shape)
    

    This works fine and in efficient way for me.