Finding a subimage inside a Numpy image

后端 未结 5 1132
太阳男子
太阳男子 2020-12-08 03:24

I have two Numpy arrays (3-dimensional uint8) converted from PIL images.

I want to find if the first image contains the second image, and if so, find out the coordin

5条回答
  •  执笔经年
    2020-12-08 03:36

    This can be done using scipy's correlate2d and then using argmax to find the peak in the cross-correlation.

    Here's a more complete explanation of the math and ideas, and some examples.

    If you want to stay in pure Numpy and not even use scipy, or if the images are large, you'd probably be best using an FFT based approach to the cross-correlations.

    Edit: The question specifically asked for a pure Numpy solution. But if you can use OpenCV, or other image processing tools, it's obviously easier to use one of these. An example of such is given by PiQuer below, which I'd recommend if you can use it.

提交回复
热议问题