calculates the similarity between a template image and a source image.
Match = MatchTemplate(SourceImage, TemplateImage, Method);
2D matrix of type uint8
2D matrix of type uint8, numbers of rows and columns must not exceed the numbers of rows and columns of SourceImage
constant of type uint8, the following values are possible:
MATCH_LEAST_SQUARES: sum of quadratic gray value differences between source and template pixels
MATCH_CORRELATION: correlation between template image and covered part of source image
MATCH_LEAST_SQUARES_NORM: normalized sum of quadratic gray value differences between source and template pixels
MATCH_CORRELATION_NORM: normalized correlation between template image and covered part of source image
2D matrix of type double
This function calculates the similarity between a template image and a source image. The template image slides over the source image and the similarity between the template image and the part of the source image covered by it is calculated. The template image is always completely inside the source image. Therefore, the result matrix has less rows and columns than the source image.
global MATCH_CORRELATION_NORM; global IPD_PATH; SourceColorImage = ReadImage(IPD_PATH + 'demos\teaset.png'); SourceImage = RGB2Gray(SourceColorImage); TemplateColorImage = ReadImage(IPD_PATH + 'demos\cropped_image.png'); TemplateImage = RGB2Gray(TemplateColorImage); Match = MatchTemplate(SourceImage, TemplateImage, MATCH_CORRELATION_NORM); MatchList = FindBestMatches(Match, size(TemplateImage), MATCH_CORRELATION_NORM); SquareList = list(); for n = 1 : size(MatchList, 1) SquareList($ + 1) = struct('BoundingBox', cat(2, MatchList(n, :) - [1 1], [3 3])'); end; SourceHandle = figure(); ShowColorImage(SourceColorImage, 'Image with Marked Match Positions'); DrawBoundingBoxes(SquareList, [0 1 0], SourceHandle); TemplateHandle = figure(); ShowColorImage(TemplateColorImage, 'Template Image'); | ![]() | ![]() |