Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Template matching
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Implementation == In this simple implementation, it is assumed that the above described method is applied on grey images: This is why '''Grey''' is used as pixel intensity. The final position in this implementation gives the top left location for where the template image best matches the search image. <syntaxhighlight lang="c"> minSAD = VALUE_MAX; // loop through the search image for ( size_t x = 0; x <= S_cols - T_cols; x++ ) { for ( size_t y = 0; y <= S_rows - T_rows; y++ ) { SAD = 0.0; // loop through the template image for ( size_t j = 0; j < T_cols; j++ ) for ( size_t i = 0; i < T_rows; i++ ) { pixel p_SearchIMG = S[y+i][x+j]; pixel p_TemplateIMG = T[i][j]; SAD += abs( p_SearchIMG.Grey - p_TemplateIMG.Grey ); } // save the best found position if ( minSAD > SAD ) { minSAD = SAD; // give me min SAD position.bestRow = y; position.bestCol = x; position.bestSAD = SAD; } } }</syntaxhighlight> One way to perform template matching on color images is to decompose the [[pixel]]s into their color components and measure the quality of match between the color template and search image using the sum of the SAD computed for each color separately.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)