Ask Your Question
0

theory of template matching algorithm

asked 2013-09-05 13:34:56 -0600

rolly gravatar image

Hello masters. i need ur help about template matching.

my basic question is what is 'single channel' mean ? is it mean grayscale so if we have a color image, the image has '3 - channel' (RGB) ? i just want to make it sure.

in cvMatchTemplate() function, should image and template in single channel ( single channel what i mean is grayscale ) ? because i have tested the function with color image and grayscale template and it works. the template is cropped from the image that had been converted to grayscale. my second and also last question, how is cvMatchTemplate function work when the image is color and the template is grayscale ? is the image converted to grayscale automatically ?

thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-05 17:06:35 -0600

According to the doc, the only important thing is that your images are in 8 bits or 32 bits, and template and image must be in the same format. So you could use a grayscale template with a color image (until both or them are 8/32 bits) or the opposite. You could also, which is more "logical" used a grayscale template with a grayscale image, and a color template with a color image.

From what I understand from the code of crossCorr function (used by matchTemplate) is that the computation is made channel by channel, and the results are summed. You could compute template matching with each channel of a color source image and manually add results to compare.

By the way, single channel means one channel...;-) which is usually associated to grayscale, but could be something different, like a distance map (with 32 or 64 bits depth). This is not really grayscale, and could be represented in grayscale as well as in (fake) colors, like for thermal image for example. But most of the time, you could assume that single channel is grayscale.

edit flag offensive delete link more

Comments

thanks before for your answer, i really apreciate it. this is my problem, i have color image and binary template and it works. but, i don't understand how can it be.is the computation made channel by channel and the results are summed just like you said? because the template and the image are different. One is binary and the other is color.

rolly gravatar imagerolly ( 2013-09-07 10:50:42 -0600 )edit

Keep in mind that template matching returns the most probable location of the template in the image. Therefore, there is always a max, which is associated to the best position of the template, but it could be very bad. By the way, if you template is really on your image, the fact it is binary affect the whole score but not the best comparison position, as template matching consider a kind of appearance (pixel by pixel comparison, the color isn't involved).

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-09-07 17:29:15 -0600 )edit

that is what i want to know, the inside of cvMatchTemplate function does. that doesn't make sense me although the color isn't involved. color image that has 255 values compare with binary image that has only 2 values. it is still a mystery for a newbie like me.

rolly gravatar imagerolly ( 2013-09-08 13:28:10 -0600 )edit

@Mathieu Barnachon , I am trying to use a color image and a color template but i am getting an error , Most of the places where i have seen people using matchTemplate method ,they have done using grayscale image. Can you please explain if possible with an example or so as how i can use color images in template matching . It would be a great help to me.

kishankumar gravatar imagekishankumar ( 2016-01-27 02:55:01 -0600 )edit

Could you please provide your error message? I got no issue with a color image and a color template.

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2016-01-28 04:21:35 -0600 )edit

Thanks. Makes sense

vasiliyx gravatar imagevasiliyx ( 2018-12-27 19:58:52 -0600 )edit

Question Tools

Stats

Asked: 2013-09-05 13:34:56 -0600

Seen: 1,335 times

Last updated: Sep 05 '13