Ask Your Question

Max value of TemplateMatching without normalization

asked 2016-03-16 16:14:57 -0500

Papercut gravatar image


I have been using template matching for my work a lot and I know the template matching method returns "the best match" over the whole image even though there is no such shape. And if I normalize the map, the max value always hikes to the max value even though its confidence is very bad.

So I am looking for a way to calculate the max value that template matching calculation can possibly make. (It's different from max value of the map)

Let's say template image size is 10x10 with gray scale. What is the max value of the map which is created by template matching method? I am using TM_CCOEFF_NORMED but I am open to other methods too depends on how easy calculating max value is.

res = cv2.matchTemplate(img,template,method)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
// max_val is just a max value in res
// I wanna know how confident max_val is comparing to the possibly maximum value.
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-03-16 17:53:02 -0500

Tetragramm gravatar image

If you use one of the methods with _NORMED, then the max possible value is 1 (or for SQDIFF, the best is 0). Best of all, these are absolute. If your match is pretty bad, then the max value in the result will be 0.3 (for example).

The methods without _NORMED are faster, but they don't give you this check, so it's difficult to tell what the maximum value is.

edit flag offensive delete link more


Thanks! It really helped

Papercut gravatar imagePapercut ( 2016-03-17 16:04:15 -0500 )edit

Question Tools

1 follower


Asked: 2016-03-16 16:14:57 -0500

Seen: 542 times

Last updated: Mar 16 '16