Why a match score hits 100
What looked wrong
A wafer rotated 90° passed as normal. The match results gave 100 points to both the wafer in normal orientation and the rotated one. The rotated wafer did not have the same shape as the reference pattern, yet its score was the same.

Cause: the score was compared only within that image
Template matching computes how similar the image is to the template at every position and builds a score map. The old code stretched this map to 0 to 100 using the map’s own minimum and maximum. Then the highest position always scores 100, whatever the map looks like.
This score does not say “how similar is this to the reference pattern.” It only says “where in this image is the best match, relative to the rest.” That is fine for finding the position, but wrong when used to decide pass or fail.
# Old: normalize by the map's own min and max. The peak is always 100
m = cv2.matchTemplate(img, tpl, cv2.TM_CCOEFF_NORMED)
score = (m.max() - m.min()) / (m.max() - m.min()) * 100 # = 100
# Fixed: normalize by the range of values the matching mode can produce
# Normalized correlation (TM_CCOEFF_NORMED) is -1 to 1; no similarity or below scores 0
score = max(m.max(), 0) * 100
What I fixed
- For each matching mode I set the theoretical minimum and maximum score, and scored within that range. Abnormal wafers now score 10 to 50 instead of a fixed 100.
- When I need “how distinct is the peak within the image,” I do not mix it into the score. I look at a separate measure, such as the gap between the first and second peaks.
- For low-pattern images, I separately documented a decision strategy that combines phase correlation (3 to 5 times faster) with several scores.
Takeaway
Normalization changes what a score is compared against. If you do not separate an absolute reference (the theoretical range) from a relative one (rank within the image), the code finds the right position but makes the wrong decision. Before using a score as a pass criterion, I first check: “Is there any case where this score cannot be 100?”
The figure and code reproduce the principle with synthetic data. They are not code or images from the equipment.