Image.similarity#
- Image.similarity(T: Any, metric: str = 'zncc') Any[source]#
Locate template in image
- Parameters:
T (ndarray(N,M)) – template image
metric (str) – similarity metric, one of: ‘ssd’, ‘zssd’, ‘ncc’, ‘zncc’ [default]
- Raises:
ValueError – template T must have odd dimensions
ValueError – bad metric specified
- Returns:
similarity image
- Return type:
Imageinstance
Compute a similarity image where each output pixel is the similarity of the template
Tto the same-sized neighbourhood surrounding the corresponding input pixel in image.Example:
>>> from machinevisiontoolbox import Image >>> crowd = Image.Read("wheres-wally.png", mono=True, dtype="float") >>> T = Image.Read("wally.png", mono=True, dtype="float") >>> sim = crowd.similarity(T, "zncc") >>> sim.disp(colormap="signed", colorbar=True); <matplotlib.image.AxesImage object at 0x7f076d628e60>
Note
For NCC and ZNCC the maximum similarity value corresponds to the most likely template location. For SSD and ZSSD the minimum value corresponds to the most likely location.
Similarity is not computed for those pixels where the template crosses the image boundary, and these output pixels are set to NaN.
- References:
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 11.5.2.
Important
Uses OpenCV function
cv2.matchTemplatewhich accepts multiple-channel, CV_8U or CV_32F images.- Seealso: