Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Why is max not equal to beta after using normalize?

I'm doing a simple template matching on an RGB image with an RGB template cut from that exact image (so I know the template has a 100% match). After running cv2.matchTemplate(subject, template, cv2.TM_CCORR), I get a match image with some values.

In order to visualize it, I then use cv2.normalize(match, 0, 255). The visualization looks nice: The resulting image has bright spots on potential matches. After that operation, I would expect the max value of the resulting array to be 255. However, np.max(normalized) returns 0.709. What is it that I have misunderstood?

My full code is here:

template = cv2.imread("template.png")
subject = cv2.imread("subject.png")

match = cv2.matchTemplate(subject, template, cv2.TM_CCORR)
normalized = cv2.normalize(match, 0, 255)
print(np.max(normalized))