The class implements exhaustive template matching algorithm, which performs complete scan of source image, comparing each pixel with corresponding pixel of template.
The class processes only grayscale 8 bpp and color 24 bpp images.
Sample usage:
// create template matching algorithm's instance ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching( 0.9f ); // find all matchings with specified above similarity TemplateMatch[] matchings = tm.ProcessImage( sourceImage, templateImage ); // highlight found matchings BitmapData data = sourceImage.LockBits( new Rectangle( 0, 0, sourceImage.Width, sourceImage.Height ), ImageLockMode.ReadWrite, sourceImage.PixelFormat ); foreach ( TemplateMatch m in matchings ) { Drawing.Rectangle( data, m.Rectangle, Color.White ); // do something else with matching } sourceImage.UnlockBits( data );
The class also can be used to get similarity level between two image of the same size, which can be useful to get information about how different/similar are images:
// create template matching algorithm's instance // use zero similarity to make sure algorithm will provide anything ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching( 0 ); // compare two images TemplateMatch[] matchings = tm.ProcessImage( image1, image2 ); // check similarity level if ( matchings[0].Similarity > 0.95f ) { // do something with quite similar images }