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:
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 corresponding input pixel in image.

Examples

>>> 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 0x741181037c20>

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

Important

Uses OpenCV function cv2.matchTemplate which accepts multiple-channel, CV_8U or CV_32F images.