python - Finding a subimage inside a Numpy image -
i have 2 numpy arrays (3-dimensional uint8) converted pil images.
i want find if first image contains second image, , if so, find out coordinates of top-left pixel inside first image match is.
is there way purely in numpy, in fast enough way, rather using (4! slow) pure python loops?
2d example:
a = numpy.array([ [0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11] ]) b = numpy.array([ [2, 3], [6, 7] ])
how this?
position = a.find(b)
position
(0, 2)
.
this can done using scipy's correlate2d , using argmax find peak in cross-correlation.
here's more complete explanation of math , ideas, , examples.
if want stay in pure numpy , not use scipy, or if images large, you'd best using fft based approach cross-correlations.
edit: question asked pure numpy solution. if can use opencv, or other image processing tools, it's easier use 1 of these. example of such given piquer below, i'd recommend if can use it.
Comments
Post a Comment