machinevisiontoolbox.Image.similarity
- Image.similarity(T, metric='zncc')
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:
Image
instance
Compute a similarity image where each output pixel is the similarity of the template
T
to the same-sized neighbourhood surrounding the corresonding 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 0x7fc7ccb5d1c0>
- 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:
Robotics, Vision & Control for Python, Section 11.5.2, P. Corke, Springer 2023.
- Seealso: