Learn Before
Example

Example of Template Matching Output Arrays

If a 4×44 \times 4 base image is compared with a 2×22 \times 2 template image, the resulting output array will be 3×33 \times 3.

# base image [[255, 255, 255, 255], [255, 255, 255, 255], [255, 255, 255, 255], [255, 255, 255, 255]] # temp image [[255, 255], [255, 255]] # output array [[1, 1, 1], [1, 1, 1], [1, 1, 1]]

This uniform output occurs because all the values of the base image match perfectly with the template image in every position. In contrast, if there are mismatches, the output array reflects the localized similarities:

# base image [[255, 0, 255, 255], [255, 255, 0, 255], [255, 255, 255, 255], [0, 255, 255, 255]] # temp image [[255, 255], [255, 255]] # output array [[0, 0, 0], [1, 0, 0], [0, 1, 1]]

0

1

Updated 2026-07-03

Tags

Python Programming Language

Data Science