![]()
Exhaustive template and block matchingAForge.NET framework provides exhaustive template and block matching routines. These are the simplest Exhaustive Template Matching
// create template matching algorithm's instance
// (set similarity threshold to 92.5%)
ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching( 0.925f );
// find all matchings with specified above similarity
TemplateMatch[] matchings = tm.ProcessImage( sourceImage, template );
// 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 );
Exhaustive Block Matching
// collect reference points using corners detector (for example)
SusanCornersDetector scd = new SusanCornersDetector( 30, 18 );
Point[] points = scd.ProcessImage( sourceImage );
// create block matching algorithm's instance
ExhaustiveBlockMatching bm = new ExhaustiveBlockMatching( 8, 12 );
// process images searching for block matchings
BlockMatch[] matches = bm.ProcessImage( sourceImage, points, searchImage );
// draw displacement vectors
BitmapData data = sourceImage.LockBits(
new Rectangle( 0, 0, sourceImage.Width, sourceImage.Height ),
ImageLockMode.ReadWrite, sourceImage.PixelFormat );
foreach ( BlockMatch match in matches )
{
// highlight the original point in source image
Drawing.FillRectangle( data,
new Rectangle( match.SourcePoint.X - 1, match.SourcePoint.Y - 1, 3, 3 ),
Color.Yellow );
// draw line to the point in search image
Drawing.Line( data, match.SourcePoint, match.MatchPoint, Color.Red );
// check similarity
if ( match.Similarity > 0.98f )
{
// process block with high similarity somehow special
}
}
sourceImage.UnlockBits( data );
|
|||||||