scikit-imagematchtemplate

Trying to understand match_template from skimage.feature


I'm trying to understand someone's code from match_template, but I couldn't understand the below process. Let's say there's a picture he's going to chop several parts. The picture is saved in:

ImagenTotal = np.asarray(Image.open('./redmangos.jpg'))

Then he selects 2 places on that picture and the coordinates are:

puntosinteres = [[189.7038558467742, 111.99546370967738],[211.1748235887097, 187.9696572580645]]

Since match_template needs two arguments - one is the original picture and another is what he's going to use to compare. Then the following process looks like this:

xinteres = int(puntosinteres[0][0]) 
yinteres = int(puntosinteres[0][1])
radio = 10
imagenband = ImagenTotal[:,:,0]
templateband = ImagenTotal[yinteres - radio : yinteres + radio, xinteres - radio : xinteres + radio, 0]
result= match_template(imagenband, templateband)
result = np.where(result>0.8)

I don't know what he's trying to do on imagenband and templateband. Could someone point me to a direction?

Thank you!


Solution

  • imagenband grabs the 0th channel from ImagenTotal, to get a single grayscale image. templateband grabs a small, 20x20 rectangle from yinteres - radio (radius in Spanish) to yinteres + radio on the rows axis and xinteres - radio to xinteres + radio on the columns axis.

    To read more on how indexing works for numpy arrays, you can read the official documentation on indexing here:

    https://numpy.org/doc/stable/user/basics.indexing.html#basics-indexing

    There are links there for more advanced indexing topics.