During geometric correction of remote sensing images, automatic point matching in the control point database may be used. There are many types of control point slice matching algorithms. The most basic classification can be divided into pixel-based vertex slice matching and feature-based vertex slice matching. Because feature-based algorithms are difficult, generally, pixel-based data is used.
First, we will briefly describe the point-to-point matching in digital image processing. template matching is an important part of digital image processing. Aligning two or more images of the same scene with different sensors or the same sensor at different times and under different imaging conditions in space, or the processing method for finding the corresponding mode from the known mode to another graph is called template matching. In short, a template is a small known image. Template matching is to search for a target in a large image. It is known that there is a target in the graph, and the target has the same size, direction, and image as the template, A certain algorithm can be used to locate the target in the graph and determine its coordinate position. [Reference 1]
For example, the light blue area on the left represents the image to be searched, and the triangle in the upper right corner represents the target, which means to locate the right positive triangle in the left graph.
General Algorithm idea: search templates
T (m × n pixels) is stacked on the S (W × H pixels) of the searched image. The template overwrites the area of the searched image, which is called the subgraph SIJ. I, j is the coordinate of the graph s in the upper left corner of the subgraph. The search range is:
1 ≤ I ≤ w-m
1 ≤ j ≤ h-n
The template matching process is completed by comparing the similarity between T and SIJ.
To measure the matching degree of template T and sub-graph Si and J, the following two measures can be used:
Or
Expand the first sub-statement to obtain the following:
From the expanded formula, we can see that the second item in the middle is a constant, that is, it is only related to the template, and the first and third items are related to the source image, as the template moves on the source image, these two values are also changing. When the value of d (I, j) is the hour, it indicates that the target is found. Through this relationship, the expanded formula can be deformed to obtain other formulas, but the principle is based on this. I will not list them here.
The efficiency of this algorithm is very low. A calculation is required for every pixel to be moved. The calculation workload is quite large. We have tested a 1000*1000 graph, the template size is 100*100, which takes about 10 minutes (the machine performance is normal, but this is really too slow ). So someone proposed the following optimization algorithm. Mainly include:
1 combination of coarse and fine matching
By observing the actual template matching operation results, we can find that the matching error near the matching point decreases rapidly, which is significantly different from other locations. This feature allows you to quickly lock the approximate area of a matching point using a combination of coarse-precision matching algorithms, which can greatly reduce the number of overall matching times. Specific implementation method: first perform a rough match between several consecutive points, roughly frame the matching area, and then retrieve the best matching point one by one in the nearby area. The calculation workload can be reduced to less than 1/3, and the target extraction effect is quite good.
2. Maximum Matching Error Limit
Because we only need to find the location of the minimum matching error, we do not need to completely calculate the absolute matching error for each location, and the calculated minimum matching error is used as the maximum allowable error. If the calculation error is greater than the maximum allowable error, it is definitely not the best matching point. You can end the calculation before entering the calculation of the next matching position. If the calculation is still less than the maximum allowable error after the matching is completed, the maximum allowable error is replaced with the current error, and the point is recorded as a potential matching position. The error between the matching point and the non-matching point is often 2 ~ Three orders of magnitude. After such processing, the remaining calculation amount after matching points can be greatly reduced.
3. Out-of-order matching
The position of the target in the matching area is unknown. Non-Fixed sequence algorithms can quickly retrieve matching regions, quickly reduce the maximum matching error, reduce the calculation workload of remaining non-matching points, and reduce the overall calculation workload. For the actual operation of the photoelectric detection equipment, the target displacement angular velocity and angular acceleration are limited in the Tracking State, so that the target is usually near the center of the matching area. The best effect is to match the radiation from the center to the surrounding area.
The program will not be written. It is very simple. You can refer to the [Reference 1] link. In addition, the opencv Library provides the template matching algorithm (matchtemplate). For details, refer to the help documentation of opencv. Here we will provide a simple description of its function:
CV_EXPORTS_W void cv::matchTemplate (const Mat & image, const Mat & templ, /*CV_OUT*/ Mat & result, int method);
The meaning of the four parameters is quite understandable. The first parameter is the search image, the second parameter is the template image, the third parameter is the search result image, and the fourth parameter is the matching method, the following six types of values correspond to different algorithms.
Cv_tm_sqdiff square difference matching method: This method uses square difference for matching; the best matching value is 0; the worse the matching, the larger the matching value.
Cv_tm_ccorr correlation matching method: This method adopts multiplication. A greater value indicates a better matching degree.
Cv_tm_ccoeff correlation coefficient matching method: 1 indicates perfect matching;-1 indicates the worst matching.
Cv_tm_sqdiff_normed normalized squared difference matching method
Cv_tm_c1__normed normalization Correlation Matching Method
Cv_tm_ccoeff_normed normalization correlation coefficient matching method
Shows the matching effect of opencv:
(Source: http://www.cnblogs.com/xrwang/archive/2010/02/05/MatchTemplate.html)
)
For information on how to use opencv template matching, refer to the URL
Http://www.cnblogs.com/xrwang/archive/2010/02/05/MatchTemplate.html
. On the surface, the goal matching method of opencv uses the previous analysis method. In fact, it actually does a lot of internal processing, for example, building a pyramid to roughly calculate the scope from the top layer, and then calculating it in detail, and comparison using Fourier transform (if not processed, the computation speed is extremely slow ). Next, we will write out the template matching principle of opencv.
(Csdn is still disgusting. I wrote it in Windows Live write. When I published it, I said I had sensitive words and I didn't find them for a long time, I had to post the content on my website and send it directly. I didn't even have any tips. What's the world !!! It is really disgusting to print on the website)