Template matching behavior - Color

asked 2018-06-14 06:05:52 -0600

Karthikeyan gravatar image

updated 2018-06-21 08:13:27 -0600

I am evaluating template matching algorithm to differentiate similar and dissimilar objects. What I found is confusing, I had an impression of template matching is a method which compares raw pixel intensity values. Hence when the pixel value varies I expected Template Matching to give a less match percentage.

I have a template and search image having same shape and size differing only in color(Images attached). When I did template matching surprisingly I am getting match percentage greater than 90%.

img = cv2.imread('./images/searchtest.png', cv2.IMREAD_COLOR)
template = cv2.imread('./images/template.png', cv2.IMREAD_COLOR)
res = cv2.matchTemplate(img, template, cv2.TM_CCORR_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
print(max_val)

Template Image : Template Image

Search Image : Search Image

Can someone give me an insight why it is happening so? I have even tried this in HSV color space, Full BGR image, Full HSV image, Individual channels of B,G,R and Individual channels of H,S,V. In all the cases I am getting a good percentage.

Any help could be really appreciated.

EDIT:

image description

edit retag flag offensive close merge delete

Comments

1
LBerger gravatar imageLBerger ( 2018-06-14 12:19:45 -0600 )edit

@LBerger: Thanks for pointing me a resource, Do you have any write up or blog I couldnt able to interpret the results I am getting.

Karthikeyan gravatar imageKarthikeyan ( 2018-06-18 23:36:46 -0600 )edit

I haven't got any blog. But Have you got a problem with this code?

LBerger gravatar imageLBerger ( 2018-06-19 06:52:59 -0600 )edit

I am not familiar with the frequency domain operations. Not getting intuition like the OpenCV's template matching

Karthikeyan gravatar imageKarthikeyan ( 2018-06-21 02:28:09 -0600 )edit

it's here https://github.com/LaurentBerger/Colo... give color images as parameters (image and template) and result is imgcorr. imgcorr is a real images (CV_64F). you can call minMaxLoc to find maximun location

LBerger gravatar imageLBerger ( 2018-06-21 07:53:10 -0600 )edit

@LBerger: Added the result of your code. what is the level parameter?

Karthikeyan gravatar imageKarthikeyan ( 2018-06-21 08:15:22 -0600 )edit

Try new version it's much better

LBerger gravatar imageLBerger ( 2018-06-23 15:15:31 -0600 )edit