template matching example with a color image leads to Value Error.

Raphael Ackermann raphael.ackermann at gmail.com
Fri Nov 15 15:00:17 EST 2013


Hi

I am trying to do template matching. Running 
http://scikit-image.org/docs/0.9.x/auto_examples/plot_template.html#example-plot-template-py  
works perfectly fine. But when I change image = data.coins() --> image = 
data.lena() to have a non b/w image I get the following error.

Traceback (most recent call last):
  File "/..../template_matching.py", line 11, in <module>
    result = match_template(image, coin)
  File 
"/usr/local/lib/python2.7/dist-packages/scikit_image-0.9.3-py2.7-linux-x86_64.egg/skimage/feature/template.py", 
line 80, in match_template
    result = _template.match_template(image, template)
  File "_template.pyx", line 50, in 
skimage.feature._template.match_template (skimage/feature/_template.c:1967)
ValueError: Buffer has wrong number of dimensions (expected 2, got 3)

Is it not possible to call match_template() with a color image? Or what am 
I doing wrong? I can't find anything in the documentation or the code that 
this should only work for black and white images.

When I replace the scikit-image algorith with one from cv2  
result = match_template(image, coin)     -->  result = 
cv2.matchTemplate(image, coin, cv2.TM_CCOEFF_NORMED)

I can at least continue further in the example and it finds the coordinates 
where the template matches.

Is this a bug? If not the documentation/example should be updated to make 
it clear that this only works for b/w images.

Thanks
Raphael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20131115/cda24668/attachment.html>


More information about the scikit-image mailing list